Aras Innovator Platform

How to Use the “Change” Data Store Event

The following sample code demonstrates how to update a property’s value in the data store. Change event methods have the following parameters available:

  • itemId – the GUID of the current context item
  • name – the name of the property being updated
  • value – the property value being validated. For item properties, this is an object with the selected item’s id, type, and keyedName.

Use Case: All Parts with the “Software” classification should have a name prefixed with “SW – “.

Solution: Create the following method and configure it as a Change event on the name property of the Part ItemType.

...

const itemNode = aras.itemsCache.getItem(itemId) || aras.itemsCache.getItemByXPath(`//Item[@id="${itemId}"]`);

if (aras.getItemProperty(itemNode, ‘classification’, '') !== ‘Software’) {

return;

}

const prefix = ‘SW - ';

if (value.substring(0,5) === prefix) {

return;

}

aras.setItemProperty(itemNode, name, prefix + value);

...