The following script can be used as a post-action on “Create” transition to copy users from a custom assets management field to request participants field (the users will be merged together):
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption;
/* Configuration */
log.info("Setting Up Custom Fields...");
def assetsCustomFieldId = 1;
def requestParticipantsCustomFieldId = 2;
/* Custom field with the value to filter on */
CustomField assetsCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(assetsCustomFieldId);
def assetsValue = issue.getCustomFieldValue(assetsCF);
log.info("Assets Custom Field value is:" + assetsValue);
if (assetsCF == null || assetsValue == null) {
return true;
}
/* Insight custom field to set */
CustomField requestParticipantsCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(requestParticipantsCustomFieldId);
log.info("Request Participants Custom Field value is:" + requestParticipantsCF);
if (requestParticipantsCF == null) {
return true;
}
/* Get Insight IQL Facade from plugin accessor */
log.info("Setting Up IQL Facade");
Class iqlFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade");
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(iqlFacadeClass);
/* Specify the schema id as well as the IQL that will fetch objects. In this case all objects with Name matching the valueCF, be sure to include " around value */
log.info('Retrieved assets value: ' + assetsValue);
def additionalRequestParticipants = [];
for(assetsObj in assetsValue) {
def username = assetsObj.label
def user = ComponentAccessor.getUserManager().getUserByName(username)
additionalRequestParticipants.add(user)
}
log.info('The following participants will be added: ' + additionalRequestParticipants);
def currentRequestParticipants = issue.getCustomFieldValue(requestParticipantsCF);
log.info('Current participants: ' + currentRequestParticipants);
def newRequestParticipants = currentRequestParticipants + additionalRequestParticipants
log.info('The final list of participants: ' + newRequestParticipants);
MutableIssue mi = (MutableIssue) issue;
mi.setCustomFieldValue(requestParticipantsCF, newRequestParticipants);
return true;
If you have any questions, feel free to reach out! The script is tested and deployed in production.