Forums

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

How to append in automation an array of values into multiple user field

Diogo Rodrigues March 22, 2025

Hello,

 

I've approvers field that I want to populate with data from multiple attributes in the linked asset.

I'm able to get the array from one attribute and set it into approvers.

However when I want to append another array I fail to succeed.

 

I'm able to append a single user using the update option using this documentation example:

 

{ "update":

{

"customfield_12345": [{

"add": { "value": "{{issue.customfield_12224}}" }

}]

}

}

 

However using the array it returns success but not appending values:

{ "update" :

{ "customfield_12345" : [ {

"add" : {{MyAssetField.AssetAtribute.flatten.asJsonObjectArray("id")}}

} ]

}

}

1 answer

1 accepted

0 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 22, 2025

Hi @Diogo Rodrigues 

For a question like this, context is important for the community to help.  Please post the following:

  • an image of your complete automation rule in a single image for continuity
  • images of any relevant actions / conditions / branches
  • an image of the audit log details showing the rule execution

Until we see those...

 

In the examples you show, you appear to be adding two completely different values to customfield_12345: a single field value and an asset attribute.

First, have you tested the contents of your asset attribute contain what you expect?

Next, you are attempting to use the function asJsonObjectArray() incorrectly in two ways: with the wrong attribute of "id" versus "value", and trying to add an array within an array.

Finally, if your source information is indeed from an asset value, those are looked up just-in-time, and so there could be timing problems when the value is not provided fast enough to be used in the dynamic JSON expression.

 

Let's assume your asset data {{MyAssetField.AssetAttribute.flatten}} produces a comma-separated values list.  To solve the timing problem, that could be stored with Create Variable.  That variable could then be split() into a list, and iterated to create the dynamic JSON expression in the Edit Issue action (recently renamed to Edit Work Item action).

  • action: create variable
    • name: varAssetData
    • smart value: {{MyAssetField.AssetAttribute.flatten.join(",")}}
  • action: Edit Issue, with advanced edit and a JSON expression
{
"update": {
"customfield_12345": [
{{#varAssetData.split(",")}}
{ "add": { "value": "{{.}}" } } {{^last}},{{/}}
{{/}}
]
}
}

 

Kind regards,
Bill

Diogo Rodrigues March 23, 2025

Hi @Bill Sheboy  thank you for replying.

 


I'm doing the same strategy for "fields" option and it works.

So proving more context.

  • Issue Linked with Asset.
  • Asset has 2 user attributes "System Owner" and "Process Owner" with 1 or more users.
  • I want to copy those users from those 2 attributes to my issue approvers that is a multiuser field.

 

I'm able to do the first copy as I'm using "fields" option under "additional fields" with following code:

Screenshot_1.jpg

 

I'm doing re-fetch to give some time to the first edition be processed.

 

However when I'm trying to update to append the 2nd attribute users and I fail to succeed.

I'm trying this code, that is the exact strategy as for Fields option:

Screenshot_2.jpg

 

The array (id) give function gives me the id format that we need as we can see in the log.

The log says the issue was successfully edited, but data is not appended.

 

Screenshot_3.jpg

 

 

BTW tested your code and returns error:

 

Error while parsing additional fields - Mismatched start/end tags: null != in template-9b3fxxxxxxxxxxxx
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 23, 2025

Thank you for the additional information.

When using the "add" operation for the field, there can only be one value in the JSON, not a list of values.  That is why the iteration technique I noted is required to include an "add" expression for each one.

If instead you want to "set" the value to replace all of the values in the field, use the "fields" syntax as that is the same as using "update" with "set".

Diogo Rodrigues March 24, 2025

Understood. Actually I want to append information.

I used fields to set the info from 1st attribute. and want to append information from 2nd attribute.

I tried your suggestion but returned:

Error while parsing additional fields - Mismatched start/end tags: null != in template-9b3fxxxxxxxxxxxx
Diogo Rodrigues March 25, 2025

Hi @Bill Sheboy any suggestion on the correction of the code to overcome the error outcome?

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 25, 2025

Sorry for the delay in responding; with the community site updates, some of the notifications were not working well.

Please post images of:

  • the complete current rule, in a single image for continuity
  • an image where the variable is created
  • an image of the edit issue action showing the advanced edit with the JSON expression

Thanks!

Diogo Rodrigues March 29, 2025

Hello,

 

here it is. 

 

Screenshot_4.jpg

Screenshot_5 (2).jpg

Thanks

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 29, 2025

Oops...typo as the pound sign # is missing from my earlier post.  Please use this:

 

{
"update": {
"customfield_10003": [
{{#varSystemOwners.split(",")}}
{
"add": {
"value": "{{.}}"
}
} {{^last}},{{/}}
{{/}}
]
}
}
Diogo Rodrigues April 3, 2025

Hi @Bill Sheboy thanks for the reply, it is better but unfortunately still does not work.

 

I get the values in log from variable. The log says it was edited, but values are not appended to the field.

 

Screenshot_8.jpgScreenshot_9.jpg

 

Diogo Rodrigues April 3, 2025

Hi,

I've manage to solve it, not in the most pretty way.

It seems that I cannot use array in update/add options.

Tested with constants and the correct syntax is this one:



{
  "update": {
    "customfield_10003": [
{
"add": { "id": "61balbalblablab" }
},
{
"add": { "id": "71blablablabla" }
}
]
  }
}

 

So, what I've done was to create 3 variables.

  • varA for the results of first array
{{issueField.AssetAttributeA.flatten.asJsonObjectArray("id")}}
  • varB for the results of second array
{{issueField.AssetAttributeB.flatten.asJsonObjectArray("id")}}
  • varC to concatenate varA and varB, splited by "," but needed to remove brackets. the closure of the varA and the opening of varB
 {{varA.replace("]","")}},{{varB.replace("[","")}} 

Then code with fields options to set all together.

{
"fields": {
"customfield_10003": {{varC}}
}
}
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.
April 3, 2025

Ah, the problem is the custom field type, and using the "id" attribute rather than "value" in that iterator because your values are IDs.

I hypothesize if you made that change in the expression I provided it will work:

{
"update": {
"customfield_10003": [
{{#varSystemOwners.split(",")}}
{
"add": {
"id": "{{.}}"
}
} {{^last}},{{/}}
{{/}}
]
}
}
Diogo Rodrigues April 4, 2025

This has worked! Thanks

Like Bill Sheboy likes this
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.
April 6, 2025

Awesome; I am glad to learn it is working!  Please consider marking this question as "answered" to help others with a similar need find solutions faster.  Thanks!

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