Friday, January 4, 2019

Set an Item to Inactive when there is no available quantity for an item

This document is to guide the users on how they can inactivate an Item via workflow when there is no available quantity.

(1) Since the value of the available quantity, which is to be used as a condition of the set field value action, cannot be obtained directly from the Workflow, a Workflow Action Script is to created. Below is a sample code:

var itemID = nlapiGetRecordId();

// Define search filters
var filters = new Array();
filters[0] = new nlobjSearchFilter( 'internalid', null, 'anyof', itemID );
// Define return columns
var columns = new Array();
columns[0] = new nlobjSearchColumn( 'quantityavailable' );

// Create the saved search
var searchresults = nlapiSearchRecord( 'item',null, filters, columns );

for ( var i = 0; searchresults != null && i < searchresults.length; i++ )
        var availQuantity = searchresults[ i ].getValue('quantityavailable');

nlapiLogExecution('DEBUG', 'availQuantity', availQuantity);
return availQuantity;  

(2) In the Workflow, a state field is to be created. It is on this field where the data coming from the script will be stored.

(3) Create a Workflow custom action, the custom action is to refer to workflow action script created in step 1.

To guide you in steps 1 to 3, you may refer here in SuiteAnswers.

(4) Create a set field value action that is to set the 'Inactive' field to checked when <field in step 2> is empty.

No comments:

Post a Comment