Assets Automation - Trigger rule based on attribute update for JSM Cloud
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
Currently, you can trigger an automation rule whenever there is an update to an object schema using the "Object" trigger.
While you can "filter" the object using an AQL condition so the rule only continues to execute if the object is from a specific object type, you can't do the same for an attribute with the AQL condition. A request for this feature is being tracked below:
- JSDCLOUD-10002 - Getting issue details... STATUS
However, we have the GET object history REST API endpoint, so we can determine which attribute was most recently updated to work around this limitation. We can use the Send web request action with this endpoint to access this information and work with the response.
Requirements
Before setting up the Send web request action in your automation rule, get the following information:
- Get your Workspace ID. You can get it by accessing this page (with "yourdomain" replaced by your actual domain): https://yourdomain.atlassian.net/rest/servicedeskapi/assets/workspace
- Make sure you have an API token. If you don't have one, follow this documentation: API tokens—Atlassian Documentation.
- Encode your credentials "<EMAIL>:<API_TOKEN>" with base64. We can do this through any online tool like Base64 encode.
The following page also has additional instructions on how to use the Send Web Request action if you want to learn more:
Solution
To get the attribute that was most recently updated, follow these steps:
- Go to your automation rule that has the Object Updated trigger.
After your Object Updated trigger, add a Send web request action and utilize this action to get the object's history via GET object history API.
In the WebhookURL section, add this URL with your <WorkspaceID>. Use the {{object.id}} smart value to replace the objectid so that we send the request for the object that triggered the rule:
https://api.atlassian.com/jsm/assets/workspace/<WorkspaceID>/v1/object/{{object.id}}/history
Use GET as the method.
- Leave "Web Request Body" as Empty.
- Enable the "Delay execution of subsequent rule actions until we've received a response for this web request"
- In the Authorization header, make sure that you add the keyword Basic followed by the base64 of your emailaddress:APItoken that you encoded earlier. So if the base64 of the emailaddress:APItoken is AB12XY45, then you would add the Basic AB12XY45 value to the Authorization header.
After the Send Web Request action is configured, we can access the response data to determine which attribute was most recently updated and whether the rule should continue or not. To do this, add a {{smart values}} condition with the following values:
- First value: {{webResponse.body.first.affectedAttribute}}
- Condition: Equals
- Second Value: <Name of the Attribute>
I'm using "Warranty" as the attribute's name in the example above. This means that the automation rule will only execute its actions (below this condition) when the attribute that was most recently changed was the "Warranty" attribute. If another attribute is changed, then the actions won't be executed.
Full automation rule:
Note
In Scenario's where you would like to capture more details of the Attribute that was Updated you can Log the Smart Value
{{webResponse.body}}
To compare the Old Value of the Attribute against its new value you can capture the following Smart Values:
- Old Value
{{webResponse.body.first.oldValue}}
- New Value
{{webResponse.body.first.newValue}}