Asset generic Groovy script

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

This guide explains how to use the [AIP] - Asset generic Groovy script post function to update asset objects when an issue transitions in your Jira workflow.

Add post function

  1. Navigate to your desired workflow in Jira.

  2. Locate the Post Function section.

  3. Add a new post function named [AIP] - Asset generic Groovy script.

The Groovy script runs only once (not for each asset). All the matching custom fields with asset objects are passed to the post function as a context parameter.

  1. Use the provided Groovy script editor to write your custom logic for updating the asset(s). Refer to the Sample Groovy scripts for examples.

  2. Put the post function in the middle after Issue Updates and before GenerateChangeHistoryFunction and Re-index post functions.

Script context parameters

The script has access to several variables containing information about the issue and assets:

Parameter

Description

Parameter

Description

Asset custom fields (with values) to inject as script parameter

Select the asset custom fields to inject as script parameters. Leave it blank to include all asset custom fields.

See context parameters for more information.

Groovy script

This is the script to be executed.

Context parameters for Groovy scripts

Variable Name

Description

Variable Name

Description

assetCustomFieldAndValueList

List of custom fields with values. Its type is List<AssetCustomFieldAndValue>.

See ScriptRunner Groovy examples and Sample Groovy scripts for asset generic Groovy script post function for examples.

issue

Access current issue. Instance of com.atlassian.jira.issue.Issue. See the Atlassian documentation for more details.

originalIssue

Access original issue before the transition. Instance of com.atlassian.jira.issue.Issue. See the Atlassian documentation for more details.

ComponentAccessor

Access Jira components. See the Atlassian documentation.

customFieldManager

Access Jira Custom Field Manager class. See the Atlassian documentation.

loggedInUser

ApplicationUser instance for the currently logged-in user. See the Atlassian documentation.

Example: loggedInUser == issue.getAssignee()

DefaultIssueChangeHolder

Default implementation of a change holder. It is used to update a custom field.

aipUtils

Helper class for the post function Groovy script. See aipUtils for details.

Try Groovy scripts

You can immediately execute a Groovy script to see the result. This will let you write and try your Groovy scripts faster.