Sample Groovy scripts for asset management in Jira workflows

This page is about Assets & Inventory Plugin for Jira DC. Using Cloud? Click here.

This page provides Groovy script examples to interact with asset custom fields and Jira issues within your Jira workflows. These scripts can be used in post functions to update asset attributes based on Jira issue transitions.

You can directly use issue or originalIssue of the transition, or fetch an issue by key or ID with Issue Manager (like anotherIssue in examples). return statements are optional but it makes the script more readable.

Get Asset's Attribute value

return aipUtils.getAttributeValueAsStringByName(asset, 'Quantity');

Example result: 40

Get Asset's Multiple Value Attribute values by name as List

import inventoryplugin.entity.JipInventoryItem; import org.apache.commons.lang3.StringUtils; String getMultipleValues() { def result = ''; def cityList = aipUtils.getMultiAttributeValueAsListByName(asset, 'Cities ListBox Multiple'); for (String city : cityList) { result += city + ', ' } return result; } return getMultipleValues();

Example result: New York, London,

Get Asset's Multiple Value Attribute values by ID as List

import inventoryplugin.entity.JipInventoryItem; import org.apache.commons.lang3.StringUtils; String getMultipleValues() { def result = ''; def cityList = aipUtils.getMultiAttributeValueAsListById(asset, 63); for (String city : cityList) { result += city + ', ' } return result; } return getMultipleValues();

Example result: New York, London,

Get Asset's Attribute values by asset object in a loop

 

Get "Text Field" JIRA custom field value

Get "Select List (single choice)" or "Radio Buttons" JIRA custom field value

Get "Select List (multiple choices)" or "Checkboxes" JIRA custom field values

You can directly use issue or originalIssue of the transition, or get another issue with IssueManager (like the example below).

 Example result: Los Angeles, San Francisco

Get old and new status name of transitioned issue

Get resolution of transitioned issue

Please note that getResolution may be null for unresolved issues. 

Get resolution of another issue

Get Created/Updated Date of an issue

If you want to assign a date or dateTime asset attribute, the value must be in ISO time format (for example, 2018-11-06T10:24:37.513).

  • For Date-Time fields, second and rest of the value will be purged automatically. Result example: 2018-11-06T10:24.

  • For date fields, minute and rest of the value will be  purged automatically. Result example: 2018-11-06.

Get Reporter/Assignee user name of an issue

If you want to assign a date or dateTime asset attribute, the value must be in ISO time format (for example, 2018-11-06T10:24:37.513).

  • For Date-Time fields, second and rest of the value will be purged automatically. Result example: 2018-11-06T10:24.

  • For date fields, minute and the rest of the value will be purged automatically. Result example: 2018-11-06.

Get Current datetime

If you want to assign a date or dateTime asset attribute, the value must be in ISO time format (for example, 2018-11-06T10:24:37.513).

  • For Date-Time fields, second and the rest of the value will be purged automatically. Result example: 2018-11-06T10:24.

  • For date fields, minute and the rest of the value will be purged automatically. Result example: 2018-11-06.