Today I received a request to add a script to check for duplicate records on a custom field before our NetSuite users saved that record.
Below is the SuiteScript for the save record event on the form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// CLIENT SCRIPT ON RECORD SAVE // CHECK FOR DUPLICATE PO NUMBER ON SALES ORDER // TODO: Maybe add entity check in case of duplicate // numeric purchase order numbers? function checkForDuplicates() { //Get the current form customer PO number to validate var customerpo = nlapiGetFieldValue('custbody_customer_po_number'); var filters = new Array(); //Create the search filter for that PO number filters[0] = new nlobjSearchFilter('custbody_customer_po_number', null, 'is', customerpo); var results = nlapiSearchRecord('salesorder', null, filters, null); if (results !== null) { //Is the result this record? if (results[0].getId() !== nlapiGetRecordId()) { //No, there is another record, ask user to confirm/cancel saving action var doWeSave = confirm('Sales Order with the PO number ' + customerpo + ' already exists.\n' + 'Click OK to save a duplicate Sales Order.\n' + 'Click Cancel to return to editing Sales Order.'); if (doWeSave) { //User selected to save the record return true; } //User selected to cancel the save return false; } } //No duplicates return true; } |
Recent Comments