Forums

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

Add array of users from an Assest object, from multiple attributes to the Approvers field

Julian Governale
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.
January 16, 2024

Edit - Tried to format code block

We are currently trying to set an array of users that are in an attribute in an asset object as approvers.

The "add" operator doesn't seem to work as the following doesn't not add any users but seems to be valid Json. Even if we tried to set a single attribute field with those array of users, it doesnt populate.

Doesnt work

{
"update": {
"Approvers": [
{
"add": {{issue.customfield_10936.Owned By.flatten.asJsonObjectArray("accountId")}},
"add": {{issue.customfield_10936.Alternate Approver.flatten.asJsonObjectArray("accountId")}}
}
]
}
}

Doesnt work

{
"update": {
"Approvers": [
{
"add": {{issue.customfield_10936.Owned By.flatten.asJsonObjectArray("accountId")}}
}
]
}

We have also tried the following with the "field" but this is invalid Json

{ "fields": 
{
"Approvers": {{issue.customfield_10936.Owned By.flatten.asJsonObjectArray("accountId")}},
{{issue.customfield_10936.Alternate Approver.flatten.asJsonObjectArray("accountId")}}
}
}

If we do just a single attribute field it works


{
"fields": {
"Approvers": {{issue.customfield_10936.Owned By.flatten.asJsonObjectArray("accountId")}}
}
}

I found a similar community post, but it doesn't deal with an array of users

https://community.atlassian.com/t5/Jira-Service-Management/Adding-Multiple-users-for-Approval-with-automation/qaq-p/1726767#U2580784

Does the add operator still work for approvers? Any suggestions on how to get this to work?

1 answer

1 accepted

1 vote
Answer accepted
Marc - Devoteam
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.
January 17, 2024

Hi @Julian Governale 

I think currently you have to use the following syntax,

{"update":{"[Approver customfield]":[{"add":{"accountId":"[User Account ID"}}]}}

I won't know if this would work in relation with assets (as I don't use it), but is the assets is containing the account id. this could work.

Julian Governale
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.
January 17, 2024

Hey Marc,

You got it, that is exactly what it is doing.  When a single attribute is pulled that contains an array of users, it returns the following which works. 

{ 
"fields":
{
"Approvers": [
{
"accountId": "5c586d0ca9655f38b8afc7bf"
},
{
"accountId": "557058:80372834-0814-4ba7-944e-47fb26eb20fb"
}
]
}
}

  Its the part of how do i add the users from another attribute into the approver after its been set, or at the same time is my issue.

It seems i may need to first set it, then set a different custom field with the other array of users, then use another edit issue action to copy the users from the custom field to the approver's field, using the add functionality in the copy operation, I'll have to test this out to validate if that works. 

Marc - Devoteam
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.
January 17, 2024

Hi @Julian Governale 

I think so that you have to do it that way, as I don't think assets information is available in that way to the API.

So you would indeed need a new CF user (multiple) to add the values to and then you the api cal to read out that field.

Julian Governale
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.
January 17, 2024

Confirmed, this is the only way that I can get this work. Sometimes just typing it out really helps! 

I'll mark this as the answer but if anyone else finds this, here is what i did

  • Edit issue Action
    • Set the array of users into the approver fields and the alternate approvers (another array of users) into a multi-user field using the advanced field section
      • Alternate Approvers is on a "View" screen only
{
"fields": {
"Approvers": {{issue.customfield_10936.Owned By.flatten.asJsonObjectArray("accountId")}},
"Alternate Approvers": {{issue.customfield_10936.Alternate Approver.flatten.asJsonObjectArray("accountId")}}
}
}
  • Re-fetched the data
  • Edit Issue operations 
    • Approvers fields - use the copy from operations
      • Copy from the current issue and copy the "Alternate Approvers" Field (Ensure "add" is checked off)
  • Clear Alternate Approvers 

I clear the field as I want the field to disappear from the details section of the request.

If the change type is updated from a P1 to an Emergency change for example, which then pulls from a different attribute field of Approvers, this automation still works as the "fields" operation does a Set and not an Add which will replace the approvers.  No need to clear the approvers fields first.

One downside to having to do it this way, it takes about 2-3 seconds longer for the rule to complete. 

Suggest an answer

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

Atlassian Community Events