Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation for Jira - using variable to edit a user picker field

Julia Foden
Contributor
March 9, 2021

Hi

I am trying to use automation when an issue is created, to set the assignee and edit another user picker field with values from 2 user picker fields in a linked issue.

I am creating 2 variables, setting the values to them in a linked issue branch, then coming back to the main line to assign and edit the created issue.

The assigning part works fine. But I can't get the edit of the other field working. The error I'm getting is invalid JSON. 

I've tried a few different ways (the variable is called pm):

{
"fields": {
"customfield_16457": {{pm}}
},
}

{
"fields": {
"customfield_16457": {{pm.accountId.asJsonObject("id")}}
},
}

What should the JSON be when using a variable? Or is this a case where a variable will not work?

2021-03-09_15-04-02.png

 

3 answers

0 votes
Julia Foden
Contributor
March 11, 2021

Hi @Gareth Cantrell and @Darryl Lee 

I was not able to use the smart value in the basic edit - it seemed not to recognise the variable as a smart value.

 

Hi @Sam Harding 

Thanks for spotting the trailing comma. Another problem with my JSON was that I didn't have "" around the smart value.

But this did not solve the problem.

It turned out that the variable was the account id, so the solution that worked was this:

{
"fields": {
"customfield_16457": { "id": "{{pm}}" }
}
}

Thanks all for your suggestions.

0 votes
Sam Harding
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 9, 2021

Hi @Julia Foden 

The answers suggested by the others in this thread are good advice, and I recommend following their suggestions. In your particular case, the reason it is not valid JSON is because of the trailing commas after your 'fields' entry. Removing the commas will make the JSON valid.

Cheers

Sam

0 votes
Gareth Cantrell
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.
March 9, 2021

Hi @Julia Foden 

It would be easier to select the field to edit from the Edit issues configure screen and use the smart value directly.

If you must use the Advanced editor, the JSON should have a single "fields" key with all the fields listed inside as follows:

{
"fields": {
"customfield_1234": "...",
"customfield_5678": "..."
}
}

Also, as @Darryl Lee mentioned in this thread, you could also use a JSON validator such as https://jsonlint.com/ to validate your JSON. 

Darryl Lee
Community Champion
March 9, 2021

Agree with Gareth - I believe you should be able to use {{pm.accountId}} in the Basic Edit function without having to deal with JSON at all:

The UI is a bit fiddly though: Screen Shot 2021-03-09 at 12.09.18 PM.png

You have to start typing {{ for it to show that Smart values are valid there. 

Also, I don't think you'll need to use asJsonObject("id").

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events