Automatically add request participants on SD ticket creation

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

Accepted Answer
0 votes

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
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,974 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you