Friday, May 24, 2019

Check if the PO# being set on a Sales Order is already used by the customer

There are instances when a user would like to make sure that the PO#s being set on the Sales Orders belonging to the same customer are not to be duplicated.

Such use case may be met by using a client side script such as below:

function onSave(){

           var poNum = nlapiGetFieldValue('otherrefnum');
           var customer = nlapiGetFieldValue('entity');
           var filter = new nlobjSearchFilter('entity', null, 'is', customer);
           var column = new Array();
           column[0] = new nlobjSearchColumn('internalid');
           column[1] = new nlobjSearchColumn('otherrefnum');
           var searchResults = nlapiSearchRecord('salesorder',null, filter,column);
           for(var i = 0; searchResults != null && i < searchResults.length; i++){
                   var searchResult = searchResults[i];
                   var soID = searchResult.getValue('internalid');
                   var soPONum = searchResult.getValue('otherrefnum');
                   alert('Checking existing PO#s for customer. Please wait.');
                   if(soPONum == poNum){
                           alert('PO# is already used by this customer');
                           return false;

This serves as an alternate solution for Enhancement#266363.

No comments:

Post a Comment