Wednesday, May 8, 2019

SuiteScript: Disallow Users from deactivating departments that are associated to an item via scripting

To disallow users from deactivating departments that are associated to an item via scripting, we can use the sample script below and deploy it through a User Event script on before submit trigger for Department record.

function checkDep(){
 if (nlapiGetFieldValue('isinactive')=='T'){
  var searchFilters = new Array();

  searchFilters[0] = new nlobjSearchFilter('department',null,'is',nlapiGetRecordId());
  var searchColumns = new Array();

  searchColumns[0] = new nlobjSearchColumn('internalid');
  var items = nlapiSearchRecord('inventoryitem', null, searchFilters, searchColumns);
 
  if (items.length>0) {
 throw 'Unable to Deactivate Department. '+items.length+' item/s use/s it.';
  }

 }

}


No comments:

Post a Comment