Example 1: Managing inventories on issue transition

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

This document explains how to track and update asset quantity based on Jira issue workflow transitions using post functions.

Scenario

In this example, we'll demonstrate how to decrease the quantity value of an asset that is attached to a Jira issue on Done workflow transition.

Instructions

  1. Define a Quantity attribute.

  2. Add it to the desired form.

  3. Create an asset and set a Quantity value (for example, 50).

  1. Define the post function to update the quantity.

    • Add [AIP] - Update Asset workflow post function to the workflows to update an asset object on transition.

    • Select Quantity field.

    • Leave the Form parameter blank to set any matching form.

Post function Groovy script

import inventoryplugin.entity.JipInventoryItem; import org.apache.commons.lang3.StringUtils; // as field is a Text type we need to convert value to int and return as String String getNewQuantityValueOfAsset() { def stringValue = StringUtils.trim(aipUtils.getAttributeValueAsStringByName(asset, 'Quantity')); if (stringValue != null && stringValue.isInteger()) { int intValue = stringValue as Integer; intValue--; return intValue as String; } else { return stringValue; } } // "null" result won't update asset. Return '' if you want to clear attribute value if(assetStatus=='removed') return null; return getNewQuantityValueOfAsset();

aipUtils.getAttributeValueAsStringByName returns the Quantity attribute value of the asset.

"return null" result won't update the asset. If you want to clear attribute value use "return ''".

  1. Test it on the Post Function Create screen and publish the workflow.

  2. Change the status of the issue to execute the post function.

In this example, the post function is configured for Done transition. Quantity is changed from 50 to 49.

Before: quantity=50

After, quantity=49

Asset view:

Â