Skip to main content

Groovy Script – Distribute Placeholder to Users, Roles, Organisations, and Groups (in a single transmittal)

Updated over a week ago

Description: Sample Groovy script to distribute a Placeholder to users (identified via email ID), roles, organisations, and groups with configurable action names, due dates, and notification settings in a single transmittal.

NOTE: Multiple distribution actions can be applied in a single execution.

The following system actions are supported when distributing a placeholder:

  • SystemAction.FOR_COMMENT

  • SystemAction.FOR_DISTRIBUTION

  • SystemAction.FOR_INFORMATION

  • SystemAction.FOR_PUBLISHING

Context: Document

Document Type: Placeholder

Remark: Accessible in Post task mode only.

Script:

def execute(){

String sendNotification = "true"; // true/false to send email notification or not

List<Map<String, Object>> distributionList = new ArrayList<>();

def emails = ["user1@example.com", "user2@example.com"] as Set<String>;

distributionList.add(prepareUsersDistribution(SystemAction.FOR_COMMENT, emails, sendNotification, "10"));

def roles = ["Role 1", "Role 2"] as Set<String>;

distributionList.add(prepareRolesDistribution(SystemAction.FOR_INFORMATION, roles, sendNotification));

distributionList.add(prepareRolesDistribution(SystemAction.FOR_PUBLISHING, roles, sendNotification, "60"));

def orgName = ["Org 1"] as Set<String>;

distributionList.add(prepareOrgsDistribution(SystemAction.FOR_INFORMATION, orgName, sendNotification));

def groups = ["Distribution Group 1"] as Set<String>;

distributionList.add(prepareGroupsDistribution(groups));

placeholderService.distributePlaceholder(distributionList);

}

// Method used to prepare user / email level distribution map

// 1. Action to be distributed 2. user email(s) 3. Action due days 4. send Email Notification true/false

def prepareUsersDistribution(def actionName, def distributionList, def isSendNotification, def actionDueDays = null) {

return prepareMap(actionName, distributionList, actionDueDays, isSendNotification, IGroovyConstant.DISTRIBUTION_TYPE_EMAIL);

}

// Method used to prepare role level distribution map

// 1. Action to be distributed 2. role name(s) 3. Action due days 4. send Email Notification true/false

def prepareRolesDistribution(def actionName, def distributionList, def isSendNotification, def actionDueDays = null) {

return prepareMap(actionName, distributionList, actionDueDays, isSendNotification, IGroovyConstant.DISTRIBUTION_TYPE_ROLE);

}

// Method used to prepare org level distribution map

// 1. Action to be distributed 2. Org name(s) 3. Action due days 4. send Email Notification true/false

def prepareOrgsDistribution(def actionName, def distributionList, def isSendNotification, def actionDueDays = null) {

return prepareMap(actionName, distributionList, actionDueDays, isSendNotification, IGroovyConstant.DISTRIBUTION_TYPE_ORG);

}

// Method used to prepare group level distribution map

def prepareGroupsDistribution(def distributionList){

Map<String, Object> distributionMap = new HashMap<>();

distributionMap.put(IGroovyConstant.DISTRIBUTION_LIST, distributionList);

distributionMap.put(IGroovyConstant.DISTRIBUTION_TYPE, IGroovyConstant.DISTRIBUTION_TYPE_GROUP);

return distributionMap;

}

// Common method to prepare distribution map

def prepareMap(def actionName, def distributionList, def actionDueDays, def isSendNotification, def distributionType){

Map<String, Object> distributionMap = new HashMap<>();

distributionMap.put(IGroovyConstant.ACTION_NAME, actionName);

distributionMap.put(IGroovyConstant.DISTRIBUTION_LIST, distributionList);

distributionMap.put(IGroovyConstant.IS_SEND_NOTIFICATION, isSendNotification);

distributionMap.put(IGroovyConstant.DISTRIBUTION_TYPE, distributionType);

distributionMap.put(IGroovyConstant.ACTION_DUE_DAYS, actionDueDays);

return distributionMap;

}


Did this answer your question?