Hello,
we user JIRA Service Desk for our onboarding process.
In the customer portal we have a custom field "Contact person" (single user picker).
This custom field can automatically added to the request participants via post-function (copy field to request participants).
Now we want to add specific users in addition to "Contact Person"-custom field.
For this we used the following script: How to Automatically Add Request Participants when Creating an Issue
Both works individually, but together, only the last executed job (copy field or script) of the transition to request participants is added.
The last script that was tested is the following:
package UpdateIssue import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue def requestParticipantsField = customFieldManager.getCustomFieldObjectByName("request participants") def users = (customFieldManager.getCustomFieldObjecByName("Contactperson").getValue(issue).toString() + ", username1, username2, username3, username4, username5") CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); issue.setCustomFieldValue(requestParticipantsField, users)
This added the contact person, but not the specific users.
I have searched for a long time and tested several scripts, but its never set both "variables".
Can anybody help me further? Does anyone have perhaps another idea how I get this configured?
Thank you for your answers and help!
Hi @Thanos Batagiannis [Adaptavist],
no problem.
Yes, you got it right. But that is not all ;)
The action should be executed when the issue gets created.
I would like to add the following users to the request participants:
"Contact Person" is different from issue to issue, the specific users are always the same.
Your script from your first answer works fine, only the "Contact Person" from an already exiting process is used, which is not practical because there are different users from issue to issue.
My idea was to get the current issue key to get the "Contact Person" from the current issue. But unfortunately no success.
regards, Alex
Hi Alex,
So you will need a custom post function that will be the first one in the create transition. And the script will look similar to
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
def issue = issue as MutableIssue
// given some user keys, collect the application users
def usersToAdd = ["paolo", "niki", "omar"].collect { ComponentAccessor.userManager.getUserByKey(it) }
// get the user in the user picker field
def contactPersonCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("UserPicker")
def user = issue.getCustomFieldValue(contactPersonCF) as ApplicationUser
if (user)
usersToAdd.push(user)
def requestParticipantsCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Request participants")
// set the request participants value
issue.setCustomFieldValue(requestParticipantsCF, usersToAdd)
Please let me know if this does the trick
Kind regards,
Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist],
sorry for the late reply.
But now i can say... it works! :)
That is the trick, awesome!
I only changed the "getCustomFieldObjectByName" to "getCustomFieldObject" and I had given the custom field ID.
Thank you very much for your help and your time! :)
kind regards,
Alex
P.S.: i can't mark your answer as solution.. :-/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the record: We're accomplish this with the help of JIRA Automation Plugin.
The "Edit issue" function let's you add a json under "additional fields" without selecting something using the drop down. Here we use
{
"update": {
"Request participants" : [
{
"add": {
"name":"{{Team Lead}}"
}
}
]
}
}
to add a request participant based on the value of the custom field Team Lead
(which is a single user picker).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Andreas,
I would like to do the same thing but from a mulit user picker, any idea how to achieve it ?
Thank you,
Pierre.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexander
Try something similar to the script below. I added some comments in order to make it more clear, please ping me if you have any questions
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() // a collection of the users that will be the request participants def users = [] // a jira issue that we are getting the user in a UserPicker custom field def jiraIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TAT-1") // the service desk issue to set the request participants def serviceDeskIssue = issue as MutableIssue def requestParticipantsField = customFieldManager.getCustomFieldObjectByName("Request participants") def userPicker = customFieldManager.getCustomFieldObjectByName("UserPicker") // user A comes from the UserPicker field from issue with key TAT-1 def userA = jiraIssue.getCustomFieldValue(userPicker) // we get userB from the user key def userB = ComponentAccessor.getUserManager().getUserByKey("paolo") // add all users to the collection users.add(userA) users.add(userB) // set the Request participants for the service desk isse in transition, // make sure it comes before the Update change history for an issue and store the issue in the database step serviceDeskIssue.setCustomFieldValue(requestParticipantsField, users)
regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist],
many thanks for your response! :)
The scrips looks good and works fine, but i have one more questions.
I would like to add the value of the userpicker, which was defined from the customer in the Service Desk portal and not by particular already existing issue ("TAT-1").
How is that possible? I tried the following, but it doesn't work.
def userA = customFieldManager.getCustomFieldObjectByName("UserPicker").getValue(issue)
Do you have an idea? Or did I misinterpreted your code regarding TAT-1?
Thanks for your answer!
regards, Alex
Edit: sorry, i forgot to mention..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Thanos Batagiannis [Adaptavist],
to find the current issue key and then read out the user from "Contract Person"-custom field, I have tried the following:
...
def currentIssue = issue.getKey()
def jiraIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("currentIssue")
...
But unfortunately also without success.
"Contact person" was defined from the customer in the Service Desk portal and is always different.
Is there a way to solve the case?
Thank you very much!
regards, Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
Sorry I didn't follow earlier, I was not getting any notifications.
So If I understand well you want to get the value from a UserPicker field (Contract Person) and add it to the request participants ?
And if that is the case then, under which circumstances you want this to happen ? (When an issue gets created or transitioned ? or when the Contract Person field gets updated ) ?
regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.