As an ISV for ERP systems for as long as MIBAR has been at it you get a certain feel for features customers want from ERP systems. Fortunately, most ERP system producers have the same feel, eventually these features make it into a release of the product. In some situations, a feature never makes into the product due to underwhelming popularity. Other times they add features but somehow fall short of the mark.

One feature never added to Netsuite is a warning when a duplicate purchase order is entered for a customer. Netsuite has an article detailing this feature on Suite Answers but it was somewhat limited in its design and didn’t have the warnings my customer required. In such cases we create our own. In this article, I will chronicle that modification. This logic can be applied to a custom field of your own choice or you can leave it on the customer PO field.

The first step is to add a Boolean custom body field to the Sales Order called Duplicate PO. I used the internal id custbody_mb_duplicate_po. This field is used as an override flag. When a duplicate PO is found the user is prompted to override this. This allows the user to accept a PO is duplicate without being prompted every time a sales order is changed.

Next, I created a client script which I attached to the Sales Order form. In it I created custom methods one for the field change event and the second for the save event.

The field change event was used to reset the override flag in the event a user changed a PO the override flag had to be reset so the newly entered PO would be checked.

function clientFieldChanged(type, name, linenum)
{
if(name==”otherrefnum”)
{
nlapiSetFieldValue(“custbody_mb_duplicate_po”,”F”);
}
}

The client save event was created to check if the PO is already on file for this customer. This allows two different customers to have the same PO.

function clientSaveRecord(){
// skip if the override flag was tripped
if(nlapiGetFieldValue(“custbody_mb_duplicate_po”)!=”T”)
{
// true if the PO is on file
if (poExists())
{
// ask the user if they want to override or cancel
if(confirm(“This PO is a duplicate! Press OK to override or Cancel to change it. “))
{
nlapiSetFieldValue(“custbody_mb_duplicate_po”,”T”);
return true;
}
// cancel – return false and cancel save
else return false;
}
}
return true;
}

//
//return true if a PO exists for this customer and is not null or empty
//
function poExists(recSalesOrder){
try {
var entityName = nlapiGetRecordType();
var customerPO = nlapiGetFieldValue(“otherrefnum”);
var customer = nlapiGetFieldValue(“entity”);
var tranId =  nlapiGetFieldValue(“tranid”);

if(customer ==”” || customer == null) return false;
if(customerPO ==”” || customerPO  == null) return false;

nlapiLogExecution(“debug”, “Customer PO ” ,customerPO);
nlapiLogExecution(“debug”, “Customer ” ,customer);

var filters = [new nlobjSearchFilter(“name”, null, “anyof”, customer),
new nlobjSearchFilter(‘mainline’, null, ‘is’, ‘T’),
new nlobjSearchFilter(‘otherrefnum’, null, ‘equalto’, customerPO)
];
// add the transaction id filter when its not a new SO
if(tranId != “To Be Generated”){
filters.push(new nlobjSearchFilter(“tranid”, null, “isnot”, tranId));
}
var searchResult = nlapiSearchRecord(entityName, null, filters);

/// if there was a search result then there is a duplicate PO
if (searchResult) {
return (true);
}
return false;
}
catch (ex) {
// error handler removed for brevity
alert(‘Exception is ‘ +e);
}
}

Note the check for the override flag (custbody_mb_duplicate_po). This is set to true when the user decides to override the duplicate PO warning. In such cases the PO is not checked again to avoid repetitive errors every time a sales order is saved. If the user doesn’t choose to override the function returns a false and the save is cancelled.

The poExists function creates a simple saved search that looks for a duplicate PO. If a result is returned from this search we know there is a duplicate. We take precautions inside the method to make sure the search doesn’t return the current transaction by adding a filter when we are in edit mode.

The duplicate PO check is a simple feature rich mod which can be implemented in your Netsuite instance by following this outline. You could perform duplicate checks for any custom field with a few minor changes. When an ERP system features fall short a quick script like this can give you the return you deserve from your ERP investment.

Need help with NetSuite? We can help! Learn more about our NetSuite services or schedule a free consultation

Additional NetSuite Resources

Why You’ll Love NetSuite’s Business Intelligence Dashboards

Creating a Save Search in NetSuite for Transactions With Related Records