Skip to main content
All CollectionsSystem TasksWorking with Groovy ScriptsGroovy Script Library
Groovy Script - Create New File Review or Reply to Existing File Review Comment
Groovy Script - Create New File Review or Reply to Existing File Review Comment
Updated yesterday

Description: Sample groovy script to create new file review or reply to existing file review comment

Context: Document

Remark: Supported in On-Load 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("user1@example.com", Recipient.USER, Recipient.ADD, 8, "10", usersList);

// ADD/REMOVE ROLES

JsonArray rolesList = new JsonArray();

setDistribution("Field Contractor", Recipient.ROLE, Recipient.ADD, 8, "2", rolesList);

// ADD/REMOVE GROUP

JsonArray groupList = new JsonArray();

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

setDistribution("Dist1", Recipient.GROUP, Recipient.ADD, groupList);

// ADD/REMOVE ORG

JsonArray orgsList = new JsonArray();

setDistribution("Asite Solutions", 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("false", "true", "Create Review Groovy.."));

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

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

responseJSON.add("status", addAttributes("true", "false", "Open"));

JsonElement disciplineObj = addAttributes("true", "true", "Engineer");

disciplineObj.addProperty("customAttribute", "true");

responseJSON.add("discipline", disciplineObj);

JsonObject commentDetail = new JsonObject();

commentDetail.addProperty("maxAllowedComments", "3");

commentDetail.addProperty("validationMessage", "Comment creation limit reached.");

responseJSON.add("comment", commentDetail);

JsonObject attachmentDetail = new JsonObject();

attachmentDetail.addProperty("isAttachmentMandatory", "true");

attachmentDetail.addProperty("validationMessage", "At least one file should be attached.");

responseJSON.add("attachment", attachmentDetail);

JsonObject associationDetail = new JsonObject();

associationDetail.addProperty("isAssociationMandatory", "true");

associationDetail.addProperty("validationMessage", "At least one entity should be associated.");

responseJSON.add("association", associationDetail);

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, "true");

// 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?