Page tree

Versions Compared

Key

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

...

In this example, we'll define a global transition with a custom screen (Update Asset) to increase or decrease quantity value of an asset when 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 Modified

4- Define a screen to Update Asset -

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.

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. 


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 Modified

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();

...

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 Modified

8- Update assets with Update Asset transition


First: Issue has no assets 

...