I run an agent in order to validate the form’s data. I use a field called ValidationMessage to store the validation result, if the field is empty the validation is OK, and the document must be saved. But when the agent ends, the field is empty even if it was filled within the agent. I have been verified the agent execution with the agent’s log.
This is the code:
FORMULA LANGUAGE ACTION IN FORM
@Command([RunAgent]; "ProductGroupSaveChanges");
@UpdateFormulaContext;
@If(@GetField("ValidationMessage")="";
@Do(
@Command([FileSave]);
@Command([FileCloseWindow])
);
"")
JAVA AGENT
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Log log = session.createLog("Agent Log");
log.openAgentLog();
Document doc = agentContext.getDocumentContext();
if (doc.getItemValueString("ProductGroupID").length() == 0)
{
doc.replaceItemValue("ValidationMessage", "The Product Group ID is empty...");
} else if (doc.getItemValueString("ProductGroup").length() == 0)
{
doc.replaceItemValue("ValidationMessage", "The Product Group name is empty...");
}
log.logAction(doc.getItemValueString("ValidationMessage"));
This is the code:
FORMULA LANGUAGE ACTION IN FORM
@Command([RunAgent]; "ProductGroupSaveChanges");
@UpdateFormulaContext;
@If(@GetField("ValidationMessage")="";
@Do(
@Command([FileSave]);
@Command([FileCloseWindow])
);
"")
JAVA AGENT
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Log log = session.createLog("Agent Log");
log.openAgentLog();
Document doc = agentContext.getDocumentContext();
if (doc.getItemValueString("ProductGroupID").length() == 0)
{
doc.replaceItemValue("ValidationMessage", "The Product Group ID is empty...");
} else if (doc.getItemValueString("ProductGroup").length() == 0)
{
doc.replaceItemValue("ValidationMessage", "The Product Group name is empty...");
}
log.logAction(doc.getItemValueString("ValidationMessage"));