invalid json in automation for jira

David Wuth
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.
October 14, 2020

I am trying to edit the Advanced Roadmap TEAM field. I can use the following without error as a LOG action: 

Parent team {{triggerissue.customfield_13100}}, story team {{issue.customfield_13100}}

 

But, when I try to set a field value (I want to copy the value of the custom field in the trigger issue), I get a "not valid json" error.

{ "fields":
   { "customfield_13100": {{triggerissue.fields.customfield_13100.value}}
   }
}

 

When I add quotes around the trigger issue, then I get an error that the field does not exist.

{ "fields":
   { "customfield_13100": " {{triggerissue.fields.customfield_13100.value}} "
   }
}

I cannot use the standard edit issue and select the field because the Team field from Advanced Roadmaps is not available. Remember, there are TWO Team fields in Jira now, if you use Advanced Roadmaps.

 

1 answer

1 accepted

2 votes
Answer accepted
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.
October 23, 2020

Hi @David Wuth 

I have not edited fields in the automation rules using JSON yet... I did look over the documentation and I wonder if there is an issue with how the automation is parsing within the quotation marks for the fields: https://support.atlassian.com/jira-core-cloud/docs/advanced-field-editing-json/

I saw one posting that used a method similar to you, but did not have the extra spaces within the quoted value:

{ "fields":
   { "customfield_13100": "{{triggerIssue.fields.customfield_13100.value}}"
   }
}

The documentation also shows examples using the function asJsonString, maybe something like this:

{ "fields":
   { "customfield_13100": {{triggerIssue.fields.customfield_13100.asJsonString}}
   }
}

Maybe try those to see if they help.

 

Best regards,

Bill

David Wuth
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.
October 24, 2020

Thanks, @Bill Sheboy ! The issue was the space before/after the quote marks. Now, I still had to modify the json a bit more to get it to do what I wanted. The final key change was using the ID of the custom field, not the VALUE. Here is the final working json:

{"fields":
  {"customfield_13100": "{{triggerissue.fields.customfield_13100.id}}"
  }
}

Like # people like this
Maha Eltemsah December 4, 2020

@David Wuth  

I have similar issue as yours.  I used the same JSAN you mentioned but I got below error

Can not deserialize instance of com.atlassian.jira.issue.fields.rest.json.beans.CustomFieldOptionJsonBean out of START_ARRAY token at [Source: N/A; line: -1, column: -1] (customfield_10958)

My automation rule is manually executed from an Epic. The custom field in the triggering Epic is a drop down field. So I tried below 

{"fields":
  {"customfield_13100": ["{{triggerissue.fields.customfield_13100.id}}"]
  }
}

and got below error

Can not deserialize instance of com.atlassian.jira.issue.fields.rest.json.beans.CustomFieldOptionJsonBean out of START_ARRAY token at [Source: N/A; line: -1, column: -1] (customfield_10958)

I tried without [

{"fields":
  {"customfield_13100": "{{triggerissue.fields.customfield_13100.id}}"
  }
}

Can not instantiate value of type [simple type, class com.atlassian.jira.issue.fields.rest.json.beans.CustomFieldOptionJsonBean] from JSON String; no single-String constructor/factory method (customfield_10958)

So any idea what's wrong in my Json ? 

David Wuth
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.
December 7, 2020

@Maha Eltemsah 

What type of field is your custom field? Mine was a string, which is why I enclosed it in quotes.

Maha Eltemsah December 7, 2020

@David Wuth 

It's a drop down field with 4 values. that's why I tried to add [

David Wuth
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.
December 7, 2020

@Maha Eltemsah I've not tried json with arrays, but based on this article (https://support.atlassian.com/jira-software-cloud/docs/smart-values-json-functions/) you might need to use the asJsonObjectArray function

jbill March 30, 2022

I originally got to the solution using the asJsonObjectString function.  It works as long as your not clearing the field.  When that happens, you will get an error.  I think because the asjsonfunction never fires.

I changed my solution to using the surrounding quotes because of this, and it works.  I did not try the asJsonObjectArray.  


Original solution (fails when trigger field is cleared):
{
"fields": {
"Team": "{{triggerIssue.fields.team.id.asjs}}"
}
}


The solution that works for me (Same as above):
{
"fields": {
"Team": "{{triggerIssue.fields.team.id}}"
}
}

gregg_simms November 7, 2023

I was able to get this work.

{
"fields": {"team": "{{issue.parent.team.id}}"}
}

Suggest an answer

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

Atlassian Community Events