About This Code
Brief Description:
SavedData property
Contributor:
Andrew Jones
Last Modified:
17 Jun 2002
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
This example uses the save data record to find the maximum weekly sales.The data records have Weeky_Sales and Name fields. The saved data record has MaxSales and MaxSales_Salesperson fields. The data record fields replace the agent record fields whenever Weekly_Sales is greater than MaxSales. import lotus.notes.*; import java.util.Vector; import java.lang.Float;
public class saveddataagent extends AgentBase {
public void NotesMain()
{
try
{
Session s = getSession();
AgentContext ac = s.getAgentContext();
Document agentDoc = ac.getSavedData();
Database db = ac.getCurrentDatabase();
View view = db.getView("Sales");
Document doc = view.getFirstDocument();
if (!agentDoc.hasItem("MaxSales"))
{
agentDoc.replaceItemValue("MaxSales", "0");
agentDoc.save(true, true);
agentDoc = ac.getSavedData();
}
while (doc != null)
{
Vector mvalue = agentDoc.getItemValue("MaxSales");
Vector wvalue = doc.getItemValue("Weekly_Sales");
Float maxSales = new Float((String) mvalue.firstElement());
Float weeklySales = new Float((String) wvalue.firstElement());
if (weeklySales.floatValue() > maxSales.floatValue())
{
agentDoc.replaceItemValue
("MaxSales", doc.getItemValue("Weekly_Sales"));
agentDoc.replaceItemValue
("MaxSales_Salesperson", doc.getItemValue("Name"));
}
doc.replaceItemValue("Weekly_Sales", "0");
doc.save(true, true);
doc = view.getNextDocument(doc);
}
agentDoc.save(true, true);
System.out.println("Best Sales person up-to-date is " +
agentDoc.getItemValue("MaxSales_Salesperson") +
" and sold $" + agentDoc.getItemValue("MaxSales"));
}
catch (Exception e)
{
e.printStackTrace();
}
} }
Usage / Example