Im updating a script we have in place that is adding request participants when an issue is created.
Im changing the script to use the accountId rather than username but it doesnt seem to be working. I can run the script and it doesnt give any errors but it also is not setting any request participants.
Is there an error in my code or syntax that isnt setting the request participant?
def reqParticipant = "customfield_10026"
if(issue.fields.summary == "NOOO Account Locked / Password Reset" && issue.fields.issuetype.name == "Access"){
def result = put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(reqParticipant): [[accountId: "557058:834c28b8-f9fc-4ebb-8a47-84476500b5c5","59fa01ed5556ec74b24dd362"]]
]
])
.asString()
}
Hi Alex,
Thankyou for your question.
I have answered your question through the support ticket that you submitted inside of our ScriptRunner for Jira Cloud support portal.
I have put the answer here for reference which is that the syntax to set the *accountId* must specify *id* as the key inside the *Array* as this what the field expects and that when specifying more than one account ID that you must specify a new object rather than using a comma seperated list.
Regards,
Kristian
How can you build a users variable to add the request participants based on another condition?
Let's said:
Condition 1 is true:
Request participants would be: A, B, C
Condition 2 is true:
Request participant would be: D,E, F
I'm struggling to build the final array, how can I add a new value?
This is my code
{code}
def reqPart = [accountId: '231313123123', accountId: '23423434']
reqPart.add(accountId: '456456')
{code}
I got an error when I try to add a new value on the array/list
Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Da,
Thank you for your response.
You would need to use the put entry to add entries to the Array as mentioned in the documentation page located here.
Unfortunately, it is not possible to build up the list as you want to do due to the fact that you would have multiple entries with the same key which Groovy will not permit.
Also, as mentioned in my post above you need to specify a new array per id using a structure similar to below as the API will not allow the ID's to be specified as a comma-separated list.
[id: "<AccountId Here>"], [id: "<AccountId Here>"]
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Kristian
Then... Let's imagine this scenario:
I have some users added on a multi-users custom field, and I need to add 2 more but without replacing them, in total I need to show 4 users on the CF.
How can I do that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
You would need to define the body as 4 separate Arrays using the structure shown above as this the structure the API requires and if you provide this then it will set all 4 users in the field.
I do not have any sample code to show how to do this but as I have shown the required structure you will be able to use this as a guide to help you write some code to create this structure.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Found a way:
def issueKey = 'XXXX-6308'
def customFieldName = 'Dashboard Business Owner(s)'
def dashboardOwners = [[accountId:"35345345"], [accountId:"3534535"]]
dashboardOwners << [accountId: "353453453"]
put("/rest/api/3/issue/" + issueKey)
.header("Content-Type", "application/json")
.body([
fields:[
customfield_12534 : dashboardOwners
]
])
.asString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
Thank you for confirming you managed, to resolve the issue.
If the answer here has been helpful can you please accept this so that other users can see this as a useful answer when they search for the same questions.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.