How to edit Quantity attribute of Assets Objects using automation for Assets in Cloud
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
For Assets Automation, Edit Object action only can be used for Object trigger.
JSDCLOUD-9964
-
Getting issue details...
STATUS
are the feature request raised to allow the action can be used for another trigger too. This article is the workaround for this limitation, which is editing the objects using Send Web Request action, which is via Insight REST API.
Environment
JSM Assets Cloud Premium
Scenario
Admin would like to update Object "Quantity" Attributes when Assets selected in Assets field in JSM issues. For example, when the user selects a Computer asset, the Quantity Attribute is reduced by one.
Solution
- Create Object Schema and Object type for Assets.
- In the Assets object type, add Quantity attribute and update it with the quantity of the asset, for example, 10 . Below are my example:-
- Find the Assets workspaceId , using query below using Postman . Save the workspaceId value for later
If you don't have API token, follow the steps in Manage API tokens for your Atlassian account .
https://<JSM Premium Site Name>.atlassian.net/rest/servicedeskapi/assets/workspace
Note that you will have to add the header X-ExperimentalApi : opt-in when calling this endpoint.
- From Postman, it will look as below :-
- Create Assets Custom field and add to JSM screen. For example, the name are Insight Assets.
- Then, create automation as below:-
- Choose Issue Created trigger
- Then, add Re fetch issue data action
- Then, add conditions to verify if the field not empty.
- Then, add Send Web Request trigger.
Use the Webhook URL as below . Update the workspaceID and Insight field name accordingly:-
https://api.atlassian.com/jsm/assets/workspace/<key in the workspaceID>/v1/object/{{<Key in the Assets field name>.id}}
- Add the Headers as per screenshot:-
- The Authorization header , after Basic , insert the "emailaddress:API Token" value that are encoded to Base64 . For example , if the value are "abc@test.com:123456" , paste it to the Base64 page and encode it.
- Then , use PUT for HTTP method and Custom Data for webhook body.
Then , use the Custom data as below :-
{ "attributes": [ { "objectTypeAttributeId": "<Attribute ID>", "objectAttributeValues": [ { "value": "{{#=}} {{<Assets Field name>.Quantity}} -1 {{/}}" } ] } ]}
To get the Attribute Id , open Insight and go to Object Type > Attribute . The Id beside the Quantity name are the Attribute ID. Based on my example screenshot above , my id are 182.
- Once done, Publish the workflow. It will look as screenshot :-
- Lastly, the moment of truth. Test it