Programatically adding users to Request Participants - Scriptrunner

Steven Mustari
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.
April 28, 2020

I am testing the ability to add users to the requested participant field using scriptrunner. The concept is check each entry of the Stakeholder Contact field, and if not found in Requested Participant field, add it to the list.

It seems this is close, but I can't seem to figure out why I am getting duplicate entries in the return of the Requested Participant field when testing this.If a user already exists in the Requested Participant field it seems to add them anyway. I would think the if statement would cover that scenario?

import com.atlassian.jira.component.ComponentAccessor;

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def stakeholderContact = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Stakeholder Contact"),
requestParticipants = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Request participants")

def sc = issue.getCustomFieldValue(stakeholderContact) as List,
rp = issue.getCustomFieldValue(requestParticipants) as List

sc.each{
if (rp.any {it}) rp << it
}

return rp

This will be a post function, but for this particular context it's in a scripted field (I use these to test results before adding post-functions)

Any help would be appreciated.

1 answer

0 votes
Steven Mustari
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.
May 1, 2020

I could use behaviours I suppose to do this on a screen, I was just hoping to be able to do it in a post function for mobile compatibility.

Also, of course, to understand why the above code is not working as expected.

Steven Mustari
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.
May 5, 2020

Using behaviours is not working because of this issue. Looks like it's back to the original question.

Suggest an answer

Log in or Sign up to answer