automation to edit a custom field using json (newbie alert)

Peter Degotardi November 24, 2024

I'm trying to get my head around json and failing miserably.

I have a custom field which is a drop-down list, that contains the values 0-36 & "> 3 years"

I want to run an automation comparing today's date with the date in another field and update the field with the calculated value.

customfield_12047 is the field holding the date to compare to.

customfield_12095 is the field I need to set 'Months open after agreed remediation date'.

It's easy enough with the gui to have the if "{{issue.customfield_12047.diff(now).months}} is greater than 36" then set the field value to ">3 years"

Less than 37 requires the JSON. This is as close as I've got but I'm obviously doing something fundamentally wrong.

{ "fields": { "customfield_12095": "customfield_12047.diff(now).months" } }

When run, the audit trail throws the error

Specify a valid 'id' or 'name' for Months open after agreed remediation date (customfield_12095))

Tips, tricks, pointers gratefully received (and yes, I think I have the logic right to cope with less than zero :) )

tks 

1 answer

1 vote
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2024

Hello @Peter Degotardi 

Welcome to the Atlassian community.

Reviewing this page

https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/

...for the details on setting a Single-select Custom Field, you should use code like this:

{
"fields": {
"customfield_12095" : {
"value": "{customfield_12097.diff(now).months}" }
}
}

 

Peter Degotardi November 24, 2024

Thanks! That's let me move on from the id error to :

Specify a valid value for Months open after agreed remediation date (customfield_12095)

 

Again, any pointers appreciated.

The if rule looks ok. The other rules for >1, >2, >3 years work (I'm still fiddling and have changed the numbers from when I first posed)

Jira1.png

The JSON seems right.

Jira2.png

The dropdown as defined

Jira3.png

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 24, 2024

Can you please provide screen images that show the entire rule and the details of the audit log for execution of the rule? 

I would also recommend that you use the Log action to print to the log the value of the smart value you're trying to use in the JSON.

Bill Sheboy
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.
November 25, 2024

Hi @Trudy Claspill and @Peter Degotardi 

I believe your suggestion is missing some curly brackets around the smart value expression:

{
"fields": {
"customfield_12095" : {
"value": "{{customfield_12097.diff(now).months}}" }
}
}

And...

I believe this could all be done with JSON using conditional logic to handle the case for "> 3 years" and there is no need for the if / else block: 

{
"fields": {
"customfield_12095" : {
{{#if(customfield_12097.diff(now).months.le(36))}}
"value": "{{customfield_12097.diff(now).months}}"
{{/}}
{{#if(customfield_12097.diff(now).months.gt(36))}}
"value": "> 3 years"
{{/}}
}
}
}

 

Or better still, use a lookup table with "key" values of true and false, and "values" of the two possible values.

 

Kind regards,
Bill

Peter Degotardi November 25, 2024

Thank you Bill and @Trudy Claspill, between the two of you I have it working.

Yes, the extra brackets on Trudy's suggestion were required.

Like Bill Sheboy likes this
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2024

Oops! Yes, of course a smart value needs double-curly-braces while the JSON syntax needs single curly braces.

Thanks, @Bill Sheboy !

Like Bill Sheboy likes this

Suggest an answer

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

Atlassian Community Events