Automatically add request participants on SD ticket creation

RVal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2016

Hi

I'm trying to automatically add Request Participants to Service Desk ticket on creation.

I tried both SIL script and Groovy script in post function but nothing worked. The idea is I have 3 custom fields where customer may select up to 3 approvers for the ticket and I want to be able to add them to the ticket as Request Participants. Here is what I tried.

SIL version:

// Add approvers to request participants
string approver1 = customfield_11600;
string approver2 = customfield_11601;
string approver3 = customfield_11602;
string[] participants;
//add approver1
if (!isNull(approver1)) {
        participants = arrayAddElement(participants, approver1);
}
//add approver2
if (!isNull(approver2)) {
        participants = arrayAddElement(participants,approver2);
}
//add approver3
if (!isNull(approver3)) {
        participants = arrayAddElement(participants,approver3);
}
//set request participants
if (arraySize(participants) > 0) {
        customfield_12800 = participants;
}

Groovy version (I tried adding only 1 approver in groovy version):

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IssueIndexManager


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_12800")
def approver1Field = customFieldManager.getCustomFieldObject("customfield_11600")


ArrayList<ApplicationUser> applicationUsers = new ArrayList<ApplicationUser>()
applicationUsers.add(issue.getCustomFieldValue(approver1Field))
issue.setCustomFieldValue(requestParticipantsField, applicationUsers)

Please point what I am doing wrong here. Working code example is highly appreciated.

1 answer

1 accepted

0 votes
Answer accepted
RVal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2016

What actually worked for me is the following groovy script

ArrayList allApprovers = new ArrayList();
allApprovers.add(approver1User);
allApprovers.add(approver2User);
allApprovers.add(approver3User);

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def changeHolder = new DefaultIssueChangeHolder();

def requestParticipantsField = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Request participants'};
requestParticipantsField.updateValue(null, issue, new ModifiedValue(null, allApprovers), changeHolder);
 
issue.store();

Suggest an answer

Log in or Sign up to answer