JSD ScriptRunner PostFunction Script - Add Request Participants based on multi-user picker field

I've played with this for too long now, but can't seem to figure it out.  It's working fine in the console, but when I add it as a post function to the create transition, it shows success, but doesn't seem to store to the database.  Thanks in advanced for any help you're able to provide!  I've been looking through other posts and trying different tweaks, but nothing seems to be doing the trick.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001")
def poc = customFieldManager.getCustomFieldObject("customfield_10506")
List<ApplicationUser> pocvalues = issue.getCustomFieldValue(poc) as List

ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>()
pocvalues.each {
if(it)
{ userList.add(it) }
}
return userList

MutableIssue myIssue = issue
myIssue.setCustomFieldValue(requestParticipantsField, pocvalues);

Below are the steps I have the post functions running:

  1. Creates the issue originally.
  2. ScriptRunner workflow function - Custom script post-function (inline script).
  3. Set issue status to the linked status of the destination workflow step.
  4. Stores updates to an issue (no change history is created).
  5. Re-index an issue to keep indexes in sync with the database.
  6. Fire a Issue Created event that can be processed by the listeners.

 

 

1 answer

0 vote
Joshua Yamdogo Community Champion Nov 14, 2017

Hi Carol,

Do you still need help with this? I would perhaps try using updateValue(), as it will persist the change to the database.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001")
def poc = customFieldManager.getCustomFieldObject("customfield_10506")
List<ApplicationUser> pocvalues = issue.getCustomFieldValue(poc) as List

ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>()
pocvalues.each {
if(it)
{ userList.add(it) }
}
//return userList
//MutableIssue myIssue = issue
//myIssue.setCustomFieldValue(requestParticipantsField, pocvalues)

requestParticipantsField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(requestParticipantsField), userList),new DefaultIssueChangeHolder())

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,327 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot