/
*This custom function shows how to add approvals for different stages and the following is the json format in which the approval configuration is returned to the application.
{"operation": [
{"INPUT_DATA": [
{ "StageOne": ["Sampleuser.1@xyz.com","Sampleuser.2@xyz.com"] },
{ "StageTwo": ["Sampleuser.3@xyz.com,"Sampleuser.4@xyz.com"] },
{ "StageThree": ["Sampleuser.5@xyz.com","Sampleuser.6@xyz.com"] },
{ "StageFour": ["Sampleuser.7@xyz.com","Sampleuser.8@xyz.com"] },
{ "StageFive": ["Sampleuser.9@xyz.com","Sampleuser.10@xyz.com"] }
],
"OPERATIONNAME": "ADD_APPROVAL_STAGE",
"send_immediately": "True"
} ],
"message": "Sample custom function for adding approvers",
"result": "success"}
priorityJson = requestObj.get("priority");
priority = "";
if(!"null".equals(priorityJson)) {
priority = priorityJson.get("name");
}
groupJson = requestObj.get("group");
group = "";
if(!"null".equals(groupJson)) {
group = groupJson.get("name");
}
if("High".equalsIgnoreCase(priority)) {
//global_function_3 will return the approval configuration json
approvalJson = global_function_3(group);
if(approvalJson != null) {
approvalStages = approvalJson.get("approval_stages");
//When send_immediately is set to true , the approvals will be added and the mail will be sent immediately.If there are any configuration provided for Service Templates under the Workflow tab , that will take precedence.
input_data = {"INPUT_DATA":approvalStages,"OPERATIONNAME":"ADD_APPROVAL_STAGE","send_immediately":"True"};
operations = Collection();
operations.insert(input_data);
returnJson = {"operation":operations,"message":"Approval(S) added Successfully through Custom Trigger","result":"success"};
}
//This message will be printed in the History when there is no Approval added through the script.
else {
returnJson = {"result":"success","message":"No Approval(s) set through the Script"};
}
}
//This message will be printed in the History when there is no Approval added through the script.
else {
returnJson = {"result":"success","message":"No Approval(s) set through the Script"};
}
return returnJson;