Skip to main content

Groovy Script - Fetch Details of All Forms Associated With the Current Revision

Description: Sample Groovy Script to fetch details of all Forms associated with the current revision and set aDecisionVariable accordingly. This script can be used with Workflow and with a direct System Task as well.

Context: App

App Type: Select an active app type as required.

Remark: Accessible in Pre, On-load, and Post task modes only once the document is uploaded to the Asite platform; this means the script will not work for Pre and On-load modes with the Publish document event.


Options Available to Fetch the Associated Form Messages

  • IGroovyConstant.ALL_FORM_MESSAGES_OF_ASSOCIATED_FORMS = Fetch details of all form messages of the associated forms.

  • IGroovyConstant.ORI_FORM_MESSAGE_OF_ASSOCIATED_FORMS = Fetch details of only the ORI form message of the associated forms.

  • IGroovyConstant.LATEST_FORM_MESSAGE_OF_ASSOCIATED_FORMS = Fetch details of only the latest form message of the associated forms.

  • IGroovyConstant.LATEST_ASSOCIATED_FORM_MESSAGE_OF_ASSOCIATED_FORMS = Fetch details of only the latest associated form message of the associated forms.

Script

def execute() {
/**************** Configurable Parameter Section *******************************************************/
String statusTextField = "resDetailList"; // field name of form XML
int aDecisionVaribale = 0;
boolean aDecisionUpdateRequired = false;
/******************************************************************************************************/

/* These are the following option for get associated form data
IGroovyConstant.ALL_FORM_MESSAGES_OF_ASSOCIATED_FORMS
IGroovyConstant.ORI_FORM_MESSAGE_OF_ASSOCIATED_FORMS
IGroovyConstant.LATEST_FORM_MESSAGE_OF_ASSOCIATED_FORMS
IGroovyConstant.LATEST_ASSOCIATED_FORM_MESSAGE_OF_ASSOCIATED_FORMS
*/

List<FormVO> formVOList = documentService.getAssociatedForm(IGroovyConstant.ALL_FORM_MESSAGES_OF_ASSOCIATED_FORMS);

for(FormVO formVO:formVOList){
Map<String, List<String>> valuesMap = formService.getFormFieldValues(formVO.getXmlData(), Arrays.asList(statusTextField));
if (valuesMap.containsKey(statusTextField)) {
List<String> values = valuesMap.get(statusTextField);
if(values.contains("Rejection")) {
aDecisionVaribale = 2;
aDecisionUpdateRequired = true;
break;
} else if(values.contains("Revise and Resubmit – Document request") || values.contains("Revise and Resubmit")) {
aDecisionVaribale = 1;
aDecisionUpdateRequired = true;
break;
}
}
}

if(aDecisionUpdateRequired){
List<ScriptResponseVO> responseActions = new ArrayList<ScriptResponseVO>();
ScriptResponseVO variableParamVo = new ScriptResponseVO();
variableParamVo.setResponseAction(ResponseActionEnum.UPDATE_WORKFLOW_VARIABLE);
Map<String, Object> variableParamMap = new HashMap<>();
variableParamMap.put(IGroovyConstant.DYNAMIC_ADECISION_VARIABLE, aDecisionVaribale); // You can set any value between 1 to 99 to this "aDecisionVaribale" variable
variableParamVo.setResponseObject(variableParamMap);
responseActions.add(variableParamVo);
return responseActions;
}

}

Did this answer your question?