How to edit Quantity attribute of Assets Objects using automation for Assets in Cloud

Still need help?

The Atlassian Community is here for you.

Ask the community


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

(info) 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:-
    1. Choose Issue Created  trigger
    2. Then, add Re fetch issue data  action
    3. Then, add conditions to verify if the field not empty.
    4. Then, add Send Web Request trigger.
    5. 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}}
    6. Add the Headers  as per screenshot:- 
    7. 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. 
    8. Then , use PUT for HTTP method and Custom Data for webhook body.
    9. 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.

    10. Once done, Publish  the workflow. It will look as screenshot :-   
    11. Lastly, the moment of truth. Test it
(info) This automation also can be use to update attribute with other smart value or text. For example value from other custom field. Feel free to explore the smart value at Advance your rules with smart values documentation.




Last modified on Oct 1, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.