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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Service Desk

Wy are we still using email for Service Desk workflows?

...attest to the experience of an urgent approval that gets lost in the boss’s inbox and requires that special “Please Approve” email or text message. In an age where we have distributed teams...

111 views 0 2
Read article

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