Copy two cascading field values from Parent to Sub-task

Sarath March 8, 2021

Hello I have two cascading fields, where I want to copy the value from parent to sub-task. I'm using advanced edit option to update using JSON function. I have used following lines, 

{
"update": {
"customfield_1234": [
{
"set": {
"value": "{{triggerIssue.fields.customfield_1234.value}}",
"child": {
"value": "{{triggerIssue.fields.customfield_1234.child.value}}"
}
}
}
]
"update": {
"customfield_5678": [
{
"set": {
"value": "{{triggerIssue.fields.customfield_5678.value}}",
"child": {
"value": "{{triggerIssue.fields.customfield_5678.child.value}}"
}
}
}
]
}  

but I was getting error, "json" cannot be parsed. 

Any appreciate will be helpful. Thanks.

3 answers

2 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.
March 8, 2021

Hi @Sarath 

In your sample JSON, the curly brackets are not all matched:

  • there is a missing close } for the first update
  • there is a missing close } for the overall expression

Please add those and see what happens.  Thanks!

Best regards,

Bill

Sarath March 8, 2021

Thank you @Bill Sheboy, identified that "}" are not updated correctly and using only 1 update field worked as well. 

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 8, 2021

JSON validators like https://jsonlint.com/ or a JSON-aware text editor like Vim have proven invaluable to me for checking my JSON.

Like # people like this
Sarath March 9, 2021

Thanks for the recommendation @Darryl Lee I'll check them out.

1 vote
Answer accepted
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 8, 2021

Hi @Sarath , this is because you have duplicated the "update" field in the JSON. Each custom field should be a separate key inside the "update" field as in the below example:

{
"update": {
"customfield_1234": [ ... ],
"customfield_5678": [ ... ]
}
}
Sarath March 8, 2021

@Gareth Cantrell - thank you Gareth. Using only one update function worked along with correcting number of curly brackets.

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 9, 2021

I was curious what would happen if you do have two updates in the same JSON (properly formatted). Turns out that Automation Rules does complain that the JSON is invalid, but it only acts on the second one, presumably because it reads/loads the JSON in order and the first update gets overwritten before executing.

So with this block, only the Description got updated:

{
"update":{
"summary":[
{
"set":"This is a new Summary to replace."
}
]
},
"update":{
"description":[
{
"set":"This is a new Description to replace."
}
]
}
}

(I know my indenting is not-good. I blame the Community text editor stripping the spaces. :-/)

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

@Darryl Lee a JSON object is represented as a hash table internally, so while it is not an error to have the same key appear multiple times, the properties of a hash table mean that the value of the earlier key will be overwritten if the same key is encountered later during the parsing of the JSON. 

Like Darryl Lee likes this
0 votes
Raul Pelaez _TecnoFor - Marketplace Partner_
Atlassian Partner
April 19, 2022

An example with Automation Cloud to copy two cascade fields from parent to sub-tasks

 

{
"fields": {
"customfield_10071": {"value":"{{triggerIssue.parent.customfield_10071.value}}", "child":{"value":  "{{triggerIssue.parent.customfield_10071.child.value}}"}},
"customfield_10069":  {"value":"{{triggerIssue.parent.customfield_10069.value}}", "child":{"value":  "{{triggerIssue.parent.customfield_10069.child.value}}"}}
}
}

Jonathan
Contributor
September 14, 2022

I tried this (DataCenter), but I'm getting an error:

(operation must be string (customfield_12420))

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events