Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

It is possible to track quantity of an asset with post functionswhile it is added to the issue custom field or removed from it. Please follow the steps of the following example.

Table of Contents

In this example, we'll demonstrate to define a global transition with a custom screen (Update Asset) to increase or decrease quantity value of an asset which is attached to a Jira issue on Done workflow transitionwhen it is added or removed from asset custom field. Asset won't be updated when asset won't added to the issue or removed from it.

1- Define a Quantity attribute

...

2- Add it to the desired form

3- Create

...

multiple assets and set

...

Quantity

...

values (i.e 50, 40, 30)

...

Image Added

4-

...

Image Removed

...

Define a screen to Update Asset -

Image Added

Remove asset custom field from edit and create screens. Only this screen will update assets on transition. View Issue screen will have Asset custom field as read-only.

Image Added

5- Define a new transition with Update Asset screen

In this example it is defined as All-to-self. You can define for a specific status as well. 

Image Added

Image Added


6- Define the post function to update quantity for the Update Asset transition

Select Add "[AIP] - Update Asset workflow postfunction" to the workflows to update an asset object on transition. And select Quantity field. Leave form parameter as blank to set any matching form.

...

Image Added

Post function Groovy Script

Code Block
languagegroovy
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
        if (assetStatus == 'added') intValue--
        else if (assetStatus == 'removed') intValue++
        return intValue as String
    } else {
        return stringValue
    }
}
// If you want to do nothing for assets removed from issue uncomment code.
// if (assetStatus == 'removed') return null; 
return getNewQuantityValueOfAsset();

...

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

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

This script will be executed for each assets of all custom fields that matches the configuration. Assets also includes removed assets to let you control inventory. If you want to do nothing for assets removed from issue you can use if (assetStatus == 'removed') return null

7- Test it on Post Function Create Screen and publish workflow

...

Image Added

7- Change status of the Issue to execute post function.

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

Before: quantity=50

Image Removed

After, quantity=49

Image Removed

Asset view:

...

8- Update assets with Update Asset transition


First: Issue has no assets 

Image Added

3 Phones have 50, 40, 30 Quantity values

Image Added


Issue updated with transition

Image Added



Issue updated and 2 phones are updated with have 49 and 39 quantity values

Image Added


Now 3rd asset is added

Image Added


Quantity values after update is 49, 39, 29

Image Added


Now 2 assets are removed

Image Added

Image Added


Quantity values after update is 49, 40, 30

Image Added