How to set the 'Affected Services' field from referenced services on an Assets object attribute via automation for Assets
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Purpose
To be able to set the 'Affected Services' field with the referenced services on an Assets object using automation. This is useful as the Affected Service' is not visible to non-licensed users on the portal, so it is not possible for customers to select.
In this case, the customer can select an object from an Assets object custom field where the object has their relevant services referenced in an attribute.
Example
Based on a schema with object types and attributes below:
Objects under this object type will have services referenced to them:
You would like to have an Assets object custom field that lists all objects in the object type, that is available for customers to use from the portal – and from there, automatically update the 'Affected services' field with the referenced services.
Solution
- On the Assets object schema and object type where you would like users to select objects from, make sure to add a 'Services' attribute that references the Services schema:
- Create Assets object Custom field that lists all objects from the above object type and add to JSM screen. Make sure this field is available in the portal as well.
- Then, create automation as below:-
- Pick Issue Created trigger (Or any trigger depending on when you would like the 'Affected services' field to be updated)
Then, add the 'Lookup objects' action. Select the Services schema and use the following query to look up all services that have a reference to the selected object on the custom field created in Step 2.
object HAVING inR(objectType = "<Object Type Name>" AND Key in ({{issue.customfield_XXXX}}))
Replace <Object Type Name> with your object type name and issue.customfield_XXXX with the custom field ID of the field created in Step 2.
Add an Edit issue action. Under 'Additional fields', in additional fields, enter the following JSON to update the 'Affected services' field:
{ "fields": { "Affected services": [ {{#lookupObjects}} {"id": "{{Service ID}}"}{{^last}},{{/}} {{/}} ] } }
- Save and publish the automation rule.
Further Reading
- Advanced Field Editing using JSON - The feature utilized above in step 3c.
- What are Operations? - The changes to OpsGenie & Services in relation to JSM.
- Assets Query Language - How the Query mentioned in step 3b can be constructed.