Automation for Revoking User Rights in Jira Using Asset Fields (edit Object Attribute)

Luka Mack
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 4, 2025

 

 

I have a customer portal where the user creates a request for revoking a user's rights. The user needs to select a user in the field "Pravice za uporabnika" (Rights for the user), id is 10313. This is an asset field that displays all users. After that, the user needs to select an application in the "Aplikacija" (Application) field, also an asset field, id is 10069, and in the final step, they need to select the right in the "Odvzem Pravice" (Revoke Rights) field, also an asset field, id is 10314. By creating this request, the process of revoking the user's rights on the selected application is triggered. Everything needs to be automated.

I started the automation in the following way:

  • The automation is currently triggered manually for testing purposes.
  • After that, I do "Lookup objects" to get the list of users currently assigned to the right from the created ticket. Schema: Skladi; Query: objecttype = Pravice AND key = ("{{issue.customfield_10314}}")
  • After that, I have the variable {{CurrentUporabniki}}; Smart value = {{lookupObjects.Uporabniki."Uporabniško ime"}}. The variable prints the current users, this is the log data: CurrentUporabniki: [user 1, user 2, user 3]
  • And the last step for now is the log that prints the user selected in the "Pravice za uporabnika" field; User: {{issue.customfield_10313."Uporabniško ime"}}. The log output is: User: user 1

The automation should remove the selected user in the "Pravice za uporabnika" field from the list of users we obtained in point 2, and then return those users back to the value of the object's attribute in the asset.

PS, I don't have Scriptrunner.

1 answer

1 accepted

1 vote
Answer accepted
Rudy Holtkamp
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 4, 2025

Create a var e.g. NewUporabniki with value:

{{NewUporabniki.concat(CurrentUporabniki.substringBefore(User).concat(CurrentUporabniki.substringAfter(User)}}

 

Luka Mack
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 4, 2025

Hello,
These are screenshots of current state.
First two screenshots will give me the list of users currently assigned to the right from the created ticket. For example CurrentUporabniki: [user 1, user 2, user 3].
2025-02-04_11h52_49.png
2025-02-04_11h57_24.png

Then this part will give me the user whi selected in the "Pravice za uporabnika" field. For example value is user 1.
2025-02-04_11h57_57.png

User 1 has to removed from the list that I've got in CurrentUporabniki var.
The last step is to edit object attribute with User 2, User 3.

2025-02-04_12h02_08.png

Where do I have to put var "NewUporabniki" from your answer?

{{NewUporabniki.concat(CurrentUporabniki.substringBefore(User).concat(CurrentUporabniki.substringAfter(User)}}"

 

Rudy Holtkamp
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 4, 2025

I assume that you have currently all users listed in the Application object in the attribute 'Username' (Google translate FTW)

You can't remove one user from an attribute, what you can do is to update the attribute with the new list, being the smart value {{NewUporabniki}}.

You need to find the following values:

  • Your workspace id: https://<siteName>.atlassian.net/rest/servicedeskapi/assets/workspace
  • The objecttype id of the Application object: {{issue.customfield_10314.id}}
  • The attribute id for the Username (find it in the object on the attribute tab, hoover over the ID column

Then you need to create a send web request action to:

PUT https://api.atlassian.com/jsm/assets/workspace/{{workspaceId}}/v1/object/{{issue.customfield_10314.id}}

Custom data:

{
"attributes": [{
"objectTypeAttributeId": "{{attributeId}}",
"objectAttributeValues": [
{{NewUporabniki.asJsonObject("value")}}
]
}]
}

Headers:

Content-Type: application/json

Authorization: Basic <API token>

Assuming that 'User 1' is the Jira accountId value and not the displayName/Email address.

Luka Mack
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 4, 2025

I tried to solve this in multiple ways, but I was unsuccessful. Can I describe the issue from the beginning once again?

When a ticket is created, the fields 'Odvzem Pravice' (Users rights) and 'Pravice za uporabnika' (User) are selected. Both fields are asset fields. The field 'Odvzem Pravice' (Users rights) is linked to the object type 'Pravice' (Rights), while the field 'Pravice za uporabnika' (User) is linked to the object type 'Employee' in Assets.

2025-02-04_15h08_20.png

I have changed the variable names to English.

In the last log, I get the data that I need to update the attribute of an object in Assets.
The problem arises with the ', ' which can appear at the beginning, in the middle, or at the end, depending on where the deleted data was located.

2025-02-04_14h59_34.png2025-02-04_15h00_36.png2025-02-04_15h00_49.png2025-02-04_15h01_52.png

I need to send this final data via API to Assets.

Thank you for the help :)

Luka Mack
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 4, 2025

Examples of last log:

[TS-140, , TS-139, TS-338]

[TS-140, TS-139, ]

I think that ", " is the main issue.

Luka Mack
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 5, 2025

@Rudy Holtkamp here is the solution.

I managed to remove the excess value, and after that, I successfully updated the attribute value of the object in Assets.
It works! :)

2025-02-05_13h43_44.png2025-02-05_13h43_57.png2025-02-05_13h44_07.png2025-02-05_13h44_18.png2025-02-05_13h44_30.png2025-02-05_13h44_48.png2025-02-05_13h45_01.png2025-02-05_13h45_16.png2025-02-05_13h46_03.png

 

Like Rudy Holtkamp likes this
Rudy Holtkamp
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 7, 2025

Nice!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events