Update asset
This page is about Assets & Inventory Plugin for Jira DC. Using Cloud? Click here.
This guide explains how to configure a workflow post function to update asset data when an issue transitions in Jira. The [AIP] - Update Asset workflow post function allows you to modify specific asset custom fields based on various conditions.
Add post function
Navigate to the desired workflow in Jira.
Locate the workflow editor and identify the transitions.
Add [AIP] - Update Asset workflow post function to the workflows.
Drag and drop the [AIP] - Update Asset workflow post function after Issue updates and before the GenerateChangeHistoryFunction and Re-index post functions.
If the condition passes, the post function is executed for each asset separately. This includes assets that are removed from the asset custom field during the transition. You can leverage the assetStatus
context parameter to control the function's behavior for removed assets.
To skip updating removed assets, add a condition within your Groovy script that checks for
assetStatus == 'removed'
. If the condition is true, returnnull
.Use
null
to indicate that you don't want to modify the asset attribute value.Use an empty string (
''
) to clear the existing value in the attribute.For practical examples, refer to the sections on Sample Groovy scripts.
Workflow parameters
Parameter | Description |
---|---|
Condition | Groovy script for the post function condition. The function must return true, or the condition must be empty to pass. If the condition fails, the post function will be ignored. |
Target Asset custom fields | Specify the custom field to update assets. Leave it blank to update all Asset custom fields. |
Default groovy script | This is the default script to be executed for the options that have no specific Groovy script. Type script returning the value to update asset attribute; for example, return |
Attributes to be updated (one or more) |
|
Groovy Scripts to execute (one for each attribute definition) | There are two options to use as source value:
Jira Custom field value will be added later as the third value source. |
Context parameters for Groovy scripts
Please see Sample Groovy scripts for asset management in Jira workflows for more examples.
Variable Name | Description |
---|---|
| Access AIP asset class instance. Only valid for Default Groovy Script and Attribute Groovy Script. |
| The string value gives the status of each asset's edit operation for Asset custom fields. This value may help with the increase or decrease decision for inventory tracking.
|
| Access current issue. Instance of |
| Access original issue before the transition. Instance of |
| Access Jira components. Refer to the Atlassian documentation. |
| Access Jira Custom Field Manager class. Refer to the Atlassian documentation. |
| ApplicationUser instance for current logged-in user. Refer to the Atlassian documentation. Example:
|
| Default implementation of a change holder. It’s used to update a custom field. |
| Helper class for the post function Groovy script. See AIP utils for details. |
Try Groovy scripts
You can immediately execute a Groovy script to see the result. This will let you write and try your own Groovy scripts faster.
Groovy examples for asset attribute types
Attribute Type | Description | Groovy example |
---|---|---|
Cascading Dropdown | The value must be cascading dropdown option IDs. Add | return "1-2" |
CheckboxList | Return valid option values wrapped with three “@” characters. For example: For a single option value, you don’t need to wrap with | return "@@@ada@@@@@@ist@@@" |
DatePicker | The result must be in ISO format ("yyyy-MM-dd"). For example, You do not need to format if you use the LocalDateTime class, as it returns in ISO format by default. Jira Issue's date field example:
| import java.time.* LocalDateTime t = LocalDateTime.now(); return (t as String) |
DateTimePicker | The result must be in ISO format ("yyyy-MM-ddTHH:mm"). For example, You do not need to do formatting if you use the LocalDateTime class, as it returns in ISO format by default. Jira Issue's date field example:
| import java.time.* LocalDateTime t = LocalDateTime.now(); return (t as String) |
DropdownList | Return a valid option value. | return "ada" |
Encrypted | The value must be text. | return "password123" |
InventoryList | Return reference asset ID. | return "3" |
InventoryListByForm | Return reference asset ID. | return "10" |
IP | Any text is possible, there is no format control. | return "10.0.0.2" |
IPv6 | Any text is possible, there is no format control. | return "2001:0db8:85a3:0000:0000:8a2e:0370:7334" |
Jira Organizations | The value must be one of Jira Organization IDs. If there are multiple values, you must add "@@@@@@" between them. | return "1" return "1@@@@@@2" |
Jira Project | The value must be one of Jira Project IDs. If there are multiple values, you must add "@@@@@@" between them. | return "10000" return "10000@@@@@@10001" |
Jira Project Components | The value must be one of "Jira Project Id - Jira Project Component Id". If there are multiple values, you must add "@@@@@@" between them. | return "10000-1" return "10000-1@@@@@@100001-2" |
Jira Project Versions | The value must be one of "Jira Project Id - Jira Project Version Id". If there are multiple values, you must add "@@@@@@" between them. | return "10000-1" return "10000-1@@@@@@100001-2" |
Jira User Picker | The value must be a username. It doesn't need to be a Jira User. | return "tyler-durden" |
TextArea | Any text is possible. | return issue.description |
URL | Any text is possible, there is no format control. | return "http://www.snapbytes.com/" |
UserPicker | Any text is possible, there is no control. You may use | return issue.reporter.username |