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

  1. Navigate to the desired workflow in Jira.

  2. Locate the workflow editor and identify the transitions.

  3. Add [AIP] - Update Asset workflow post function to the workflows.

  4. 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, return null.

  • 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

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 issue.summary.

Attributes to be updated (one or more)

  • Form: Define a specific Form or select Any form to update the assets having the attribute.

  • Attribute: Target attribute to set its value.

Groovy Scripts to execute

(one for each attribute definition)

There are two options to use as source value:

  • Use default Groovy script: Default Groovy script result will be set to the attribute value

  • Custom Groovy script: Specify attribute specific Groovy script to set as 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

Variable Name

Description

asset

Access AIP asset class instance.

Only valid for Default Groovy Script and Attribute Groovy Script.

assetStatus

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.

  • noChange: The asset already exists before the transition, and it still exists.

  • removed: The asset is removed in this transition.

  • added: The asset did not exist before the transition, and it is added in this transition.

  • unknown: A serious error occurred and failed to determine the status.

issue

Access current issue. Instance of com.atlassian.jira.issue.Issue. Refer to the Atlassian documentation.

originalIssue

Access original issue before the transition. Instance of com.atlassian.jira.issue.Issue. Refer to the Atlassian documentation.

ComponentAccessor

Access Jira components. Refer to the Atlassian documentation.

customFieldManager

Access Jira Custom Field Manager class. Refer to the Atlassian documentation.

loggedInUser

ApplicationUser instance for current logged-in user. Refer to the Atlassian documentation.

Example:

loggedInUser == issue.getAssignee()

DefaultIssueChangeHolder

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

aipUtils

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

Attribute Type

Description

Groovy example

Cascading Dropdown

The value must be cascading dropdown option IDs. Add "-" between options. 

return "1-2"
return "1-2-3-4"

CheckboxList

Return valid option values wrapped with three “@” characters. For example: @@@ada@@@@@@ist@@@

For a single option value, you don’t need to wrap with @ characters.

return "@@@ada@@@@@@ist@@@"

DatePicker

The result must be in ISO format ("yyyy-MM-dd"). For example, "2018-12-26".

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:

  • issue.created.format("yyyy-MM-dd'T'HH:mm")

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, "2018-12-26T20:20".

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:

  • issue.created.format("yyyy-MM-dd'T'HH:mm")

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 issue.reporter.username or issue.assignee.username.

return issue.reporter.username