Copy and sync Jira services into Assets custom field
Summary
This article explains how to copy/sync Jira services (Project > Operations > Services) to an Assets field in a work item. This was an existing requirement in which both fields needed to be in sync after posterior updates on services. The proposed rule uses regular expressions and automation smart values text functions.
Environment
Jira and Jira Service Management Cloud
- Assets.
- Automation.
- Smart values.
- Regular expressions.
Automation rule
Step 1. Trigger. Work item changed. The rule will execute upon an update to this field.
Step 2. Action. Create variable. This will store the affected services field names in a variable.
{{issue.affectedServices}}
Step 3. Action. Create variable. Arranged the affected services' names using automation smart values text functions, and regular expressions, taking as a reference the variable created in the previous component:
{{allservices.replaceAll("\\s*,\\s*",",").replaceAll("([^,]+)","\"$1\"")}}
Step 4. Action. Log action component. This component isn't required. However, it is very helpful to verify that the correct values are being retrieved; this has no action on the ticket. This will reflect our final variable value:
{{servicesnames}}
Step 5. Action. Edit work item. This will edit the services Assets custom field values as updated in the Affected services:
- AQL used for the above component:
Name in ({{servicesnames}})