Forums

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

Clear/Remove users from multi user field when a issue is edited

Harsh
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 14, 2023

Hi there,

Is there a way where we can remove users from a custom field which is of type - Multi User field with the help of automation or script?

I have been trying with Automation but no luck.

Below is my JSON which I am using in Automation- 

{
"update": {
"customfield_14296": [{
"remove": {"accountId":"12345"}
}]
}
}

I also tried with 'Name' but no luck. If there is a script that helps achieving it. That also works.

2 answers

1 vote
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 14, 2023

Hi @Harsh 

Please try using the user name, as shown here for Server / Data Center versions: https://confluence.atlassian.com/automation/advanced-field-editing-using-json-993924663.html

Perhaps also check the edit metadata to learn if the REST API supports removing users with rules.  That is also described in that post.

Kind regards,
Bill

Harsh
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 15, 2023

Hi @Bill Sheboy 

I did already tried it but no success.
Both set/add and remove not working.

The field is multi user field and I want to update add and remove it based on component.

Example - If component = A

then Multi user field = ABC

if component = B
then multi user field = DEF

It can have both component A & B together as well. Assuming at any point if the components A is removed I only want  user ABC to be removed and not DEF. 


Thanks!
Rohit

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 15, 2023

Would you please post images of your complete rule, the actions with the edits, and of the audit log details.  Those may provide context to help explain what you are observing.  Thanks!

Harsh
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 15, 2023

Hi @Bill Sheboy 

I can share the audit log for sure.

 

The first one shows success when I use the JSON in EDIT Action as below. It says success but user is not added nor removed(else if condition)

FOR ADD:

{
"update": {
"customfield_14296": [{
"add": {"accountId":"12345"}
}]
}
}

 

FOR REMOVE: 

{
"update": {
"customfield_14296": [{
"remove": {"accountId":"12345"}
}]
}
}

1.png2.png

 

Secondly, 
I get this error when I use JSON 

ADD:

{
"update": {
"customfield_14296": [{
"set": {"id":"12345"}
}]
}
}

4.png

And I simply get INVALID JSON error when I use NAME instead of id/accountID.

I want to achieve to simply add the names/ID for the users in multi user field.
Hope this helps

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.
November 16, 2023

In that documentation article for advanced edit with JSON, it describes how to check the edit metadata.  That will show which operations (add, remove, set) are supported for a field.  Please check that to confirm what is possible.

If that does not help, you may need to work with your site admin to contact Atlassian Support for this one: https://support.atlassian.com/contact/#/

0 votes
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.
November 14, 2023

Hi @Harsh 

I think on server its not accountId.

Cloud you try

{
  "update": {
      "customfield_14296": [{
            "remove": "id":"user_id"
        }]
     }
}

Harsh
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 14, 2023

Hi @Marc - Devoteam 

Thanks for the answer. But I have already this and I get the following error.

'Error while parsing additional fields. Not valid JSON.'

Just for info - customfield_14296 is a multi user field and have multiple users. Let assume 2. I want to remove both of them when the issue is edited.

Also, when using accountID, It shows success but the user is not removed.

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.
November 14, 2023

Hi @Harsh 

Are these the same set of users, or random?

If its random then its almost impossible.

If its always the same users, you might want to look at creating a lookup table and then take actions, but, this will also be difficult if the list is set in a random order.

Based on what action would user be removed and which users need to be removed?

Harsh
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 15, 2023

Hi @Marc - Devoteam 

I tried with script runner and it worked. 
Also I tried other method based  on smart value documentation - I edited the field with value {{null}}. In both cases it worked.


Although, to answer your question -  we are setting the user automatically based on component.

Example - If component = A

then Multi user field = ABC

if component = B
then multi user field = DEF

It can have both component A & B together as well. But in this case the logic which I told above will fail,  assuming at any point if the components A is removed I only want  user ABC to be removed and not DEF. But if I am using {{null}} it is removing all users.

And hence I am looking for a way if there is a way to update/remove the user via json. I referred the Atlassian docs but of no use.


Thanks

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.
November 16, 2023

Hi @Harsh 

If I look at the API options, for user related fields there is only the set option.

So this would mean that you would have to redefine you automation.

Are the components set on creation?

If so have a rule based on issue creation to set users based on component.

Have another rule that triggers on change on component, set validations based on options and set the user for the field.

Would that be an option?

Harsh
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 16, 2023

Hi @Marc - Devoteam 

No, the components are not created on creation, it is just selected from the list. 

 

And the automation should add the user..

I have tried with both SET and ADD.  For Set it throws the error as mentioned above

For Add it says success but nothing happens. 

"Have another rule that triggers on change on component, set validations based on options and set the user for the field" - I have added for both creation and updation both. 

 

Thanks

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.
November 16, 2023

Hi @Harsh 

If you use the following JSON

{
"fields": {
"customfield_14296": { "name": "username" }
}
}
Harsh
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 16, 2023

@Marc - Devoteam 

Let me try this for setting the users. But what should I do if I have to remove the users based on the condition? 

I'll update you on this shortly 

Thanks. 

Harsh
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 17, 2023

Hi @Marc - Devoteam 

Update, unfortunately it did work. 
It throws an error - 'data was not an array'

customfied_14296 is User Picker (multiple users) type, does this mean it is not considering the field at all?

Thanks!
Rohit 

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.
November 17, 2023

There is no remove option via JSON.

See post from @Bill Sheboy 

Checking the metadata show there is no remove or delete option via JSON.

You could contact Atlassian Support for this one: https://support.atlassian.com/contact/#/

Suggest an answer

Log in or Sign up to answer