Tuesday, May 28, 2019

Change of an Item's Inactive Field does not Trigger User Event Scripts

Prerequisite for this scenario is that an User Event script is deployed on a particular item type in order to track the change of the Inactive field (the field's internal id is isinactive).

For example an User Event script with the following AfterSubmit function is deployed on non-inventory items:

function userEventAfterSubmit(type) {     //If the record is currently being created, then there is no old value of the field and the check is not necessary.     if (type != 'create')    {         //get the old record and the old value of the Inactive field        var oldRecord = nlapiGetOldRecord();         var oldInactive = oldRecord.getFieldValue('isinactive');        //get the new record and the new value of the Inactive field        var newRecord = nlapiLoadRecord('noninventoryitem', nlapiGetRecordId());        var newInactive = newRecord.getFieldValue('isinactive');        //for testing purpose log the two values         nlapiLogExecution('DEBUG', 'oldInactive: '+oldInactive, 'newInactive: '+newInactive);        //check whether the values are different         if (newInactive != oldInactive)             {                 //if so, note this in the log                 nlapiLogExecution('DEBUG', 'Status:', 'The value of isinactive was changed.');            }     } } 

When the value of an item's Inactive field is changed this is reflected in the following places:

  • in the script's execution log,
  • in the item's system notes.

However, it can occur that the item's Inactive value is changed and the system notes show this change, but the script's execution log does not contain a reference to this change. This can happen if the item, which was changed, is a subitem. The item is a subitem when its field Subitem of is not empty.

When the parent item is set to inactive, all the subitems are also set to inactive. This does trigger UserEvent scripts on the parent item, but it does not trigger User Event scripts for the subitems. The system notes show the same time Date and Set by for the subitems as for the parent item.

Possible alternate approaches are to perform the custom logic for the subitems when the script is triggered for the parent items or to prevent users from setting parent items to inactive before setting the subitems to inactive.

An enhancement which requests triggering User Event scripts in this scenario for the subitems as well is already filed. The enhancement number is #268096.

No comments:

Post a Comment