Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Listener to add each commentor (except author and assignee) to participants Edited

Hello,

we need to add each commentor to the Participants (we have custom field for this) in the issue.

As I know it can be done using Listeners in a ScriptRunner plugin.

Now script is like

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent

def issue = event.issue as MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject(10600)

def lastcomment = event.getComment()
def commentAuthor = lastcomment.getAuthorApplicationUser()

issue.setCustomFieldValue(cf, commentAuthor)

 

It has no any errors, but commentors don`t appear in a Participants.

What`s wrong in the script ?

 

Thank you for your answers and help!

1 answer

0 votes

Is the "Participants" field the one from the Jira toolkit, or is it just a multi-user select field?

Hi, Nic.

Participants is multi-user select field.

Ok, great, that's completely clear and explains the problem.

The value of a multi-user field is not a single user, it is a list of users.   You need to get the current list, add to it and post it back.  Not set it to a single user.  Even if it could accept a single user (it can't, it needs a list, even if that list is 0 or 1 items long), that would wipe out the current list.

Hi, Nic.

Thank you for your advice.

Now it works

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

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
def issue = event.issue as MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject(10600)

def lastcomment = event.getComment()
def commentBody = lastcomment.getBody()
def commentAuthor = lastcomment.getAuthorApplicationUser()

List<ApplicationUser> participants = [];
if (commentAuthor != issue.reporter){
ApplicationUser user = commentAuthor
participants.add(user);
}
if (commentAuthor != issue.assignee){
ApplicationUser user = commentAuthor
participants.add(user);
}
if (commentAuthor == issue.reporter){
return 0
}
if (commentAuthor == issue.assignee){
return 0
}

cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), participants), changeHolder)

It could be more "code friendly", but it works like expected.

May be it will be useful for someone.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

269 views 2 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you