Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Control options available while creating a new aMessage / replying to an aMessage
Groovy Script - Control options available while creating a new aMessage / replying to an aMessage
Updated yesterday

Description: Sample groovy script to control options available while creating a new aMessage / replying to an aMessage

Options available to control are:

a) Removing default list of recipients in the 'To' field which may include one or more of users / roles / distribution groups / organisations

a) Adding New Recipients in the 'To' field which may include one or more of users / roles / distribution groups / organisations

b) Set default aMessage title

c) Set default aMessage description

d) Set 'Mark as Private' checkbox option to ticked or unticked as default

e) Make any or all of the available options non-editable - Includes 'To', 'Title', 'Description' and 'Mark as Private' checkbox option

Context: Document

Remark: Accessible in 'On-Load' task mode only

Script:

def execute(){

// Fetch current document details

DocumentVO document = documentService.getDocumentDetails();

//Prepare ADD/REMOVE Recipients JSON

JsonObject responseJSON = new JsonObject();

// ADD/REMOVE USERS

JsonArray usersList = new JsonArray();

setDistribution(document.getPublisherEmail(), Recipient.USER, Recipient.REMOVE, usersList); // Params: User Email, Type Of Recipient, ADD/REMOVE, listObject.

setDistribution("abc@example.com", Recipient.USER, Recipient.ADD, SystemAction.FOR_ACKNOWLEDGEMENT, "3", usersList); // Params: User Email, Type Of Recipient, ADD/REMOVE, Task to be assigned, Due days, listObject.

// ADD/REMOVE ROLE

JsonArray rolesList = new JsonArray();

setDistribution("Field Administrator", Recipient.ROLE, Recipient.ADD, SystemAction.FOR_COMMENT, "2", rolesList);

setDistribution("role 2", Recipient.ROLE, Recipient.REMOVE, rolesList);

// ADD/REMOVE GROUP

JsonArray groupList = new JsonArray();

setDistribution("Doc AAA", Recipient.GROUP, Recipient.REMOVE, groupList);

setDistribution("Doc BBB", Recipient.GROUP, Recipient.ADD, groupList);

// ADD/REMOVE ORG

JsonArray orgsList = new JsonArray();

setDistribution("R17 Test Inc", Recipient.ORG, Recipient.ADD, SystemAction.FOR_STATUS_CHANGE, "1", orgsList);

setDistribution("org 2", Recipient.ORG, Recipient.REMOVE, orgsList);

// Set other options of create discussion screen

responseJSON.add(IGroovyConstant.TITLE, addAttributes("true", "false", "Create Comment Reply Groovy.."));

responseJSON.add(IGroovyConstant.DESCRIPTION, addAttributes("true", "false", "Description From Groovy .."));

responseJSON.add(IGroovyConstant.MARK_AS_PRIVATE, addAttributes("true", "true", "true"));

JsonObject distributionList = new JsonObject();

distributionList.add(Recipient.USER, usersList);

distributionList.add(Recipient.ROLE, rolesList);

distributionList.add(Recipient.ORG, orgsList);

distributionList.add(Recipient.GROUP, groupList);

distributionList.addProperty(IGroovyConstant.CLEAR_DISTRIBUTION_LIST, "false"); // By setting this value to true, it will clear all the recipients from the distribution list in 'To' field.

distributionList.addProperty(IGroovyConstant.ENABLE_DISTRIBUTION_LIST,"false");

distributionList.addProperty(IGroovyConstant.APPLY_TO_EDIT_DRAFT,"true");

responseJSON.add(IGroovyConstant.DISTRIBUTION_LIST, distributionList);

document.setResponseStatus(false);

document.setDynamicObject(responseJSON.toString());

return document;

}

// Do not change anything in below functions.

// FOR REMOVE

public void setDistribution(String data, String distLevel, String operation, JsonArray arrayList) {

String ojbect = "name";

if(Recipient.USER.equals(distLevel)) {

ojbect = "email";

}

JsonObject jsonObject = new JsonObject();

jsonObject.addProperty(ojbect, data);

jsonObject.addProperty("operation", operation);

arrayList.add(jsonObject);

}

// TO ADD

public void setDistribution(String data, String distLevel, String operation, int actionId, String dueDays, JsonArray arrayList) {

String ojbect = "name";

if(Recipient.USER.equals(distLevel)) {

ojbect = "email";

}

JsonObject jsonObject = new JsonObject();

jsonObject.addProperty(ojbect, data);

jsonObject.addProperty("operation", operation);

jsonObject.addProperty("actionId", String.valueOf(actionId));

jsonObject.addProperty("dueDays", dueDays);

arrayList.add(jsonObject);

}

// PREPARE JSON

public JsonElement addAttributes(String applyToEditDraft, String editable, String defaultValue) {

JsonElement jsonObject = new JsonObject();

jsonObject.addProperty(IGroovyConstant.EDITABLE, editable);

jsonObject.addProperty(IGroovyConstant.VALUE, defaultValue);

jsonObject.addProperty(IGroovyConstant.APPLY_TO_EDIT_DRAFT, applyToEditDraft);

return jsonObject;

}



Did this answer your question?