Skip to main content

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

Updated over a month ago

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

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' mode with the Publish document event.

The options below are 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 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?