---
title: "Example 1: Managing inventories on issue transition"
canonical: "https://support.appfire.com/space/AIP/10256694/Example%201%3A%20Managing%20inventories%20on%20issue%20transition"
format: markdown
---
> Macro (aura-html)

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).

4. 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

```groovy
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 ''"`.

5. Test it on the *Post Function Create* screen and publish the workflow.
6. 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`.

**Asset view:**

![image](media://d5c8ef99-2637-4fdc-b2cd-27355fe4b213)