SophieGadrey
11/09/2021, 3:47 PM/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord', 'N/log', 'N/record', 'N/search'],
/**
* @param{currentRecord} currentRecord
* @param{log} log
* @param{record} record
* @param{search} search
*/
function(currentRecord, log, record, search) {
/**
* Function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @since 2015.2
*/
function fieldChanged(scriptContext) {
var currentRec = scriptContext.currentRecord;
if (scriptContext.fieldId === 'otherrefnum') {
try {
var po = currentRec.getValue('otherrefnum');
var customer = currentRec.getValue('entity');
po = po.trim();
log.error('saveRecord' , JSON.stringify(scriptContext));
alert('un message important');
log.error('currentRecord' + JSON.stringify(currentRec));
var exist = searchPO(customer, po);
if (exist) {
alert('The po "' + currentRec.getText('otherrefnum') + '" already exists for the sales order.');
} else {
return true;
}
}
catch(e) {
console.log(e);
log.debug({
title: '[Error while writing PO]',
details: 'Error while writing PO' + (e)
});
}
}
}
function searchPO (entity, po){
var exist = false;
var searchPo = search.create({
type: search.Type.SALES_ORDER,
filters: [["entity","is",entity], "AND", ["otherrefnum", "is" ,po]]
});
var searchResultCount = searchPo.runPaged(currentRecord).count;
if (searchResultCount > 0) {
exist = true;
}
return exist;
}
return {
fieldChanged: fieldChanged,
//validateField: validateField,
//saveRecord: saveRecord
};
});
eminero
11/09/2021, 4:02 PMeminero
11/09/2021, 4:02 PM/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
SophieGadrey
11/09/2021, 4:03 PMSophieGadrey
11/09/2021, 4:03 PMeminero
11/09/2021, 4:03 PMSophieGadrey
11/09/2021, 4:04 PMSophieGadrey
11/09/2021, 4:05 PMeminero
11/09/2021, 4:08 PMSophieGadrey
11/09/2021, 4:10 PMSophieGadrey
11/09/2021, 4:15 PMeminero
11/09/2021, 4:28 PMSophieGadrey
11/09/2021, 4:30 PMeminero
11/09/2021, 4:32 PMbattk
11/09/2021, 4:58 PMbattk
11/09/2021, 4:58 PMSophieGadrey
11/10/2021, 8:42 AMSophieGadrey
11/12/2021, 8:42 AMNElliott
11/12/2021, 9:01 AMSophieGadrey
11/12/2021, 9:05 AMSophieGadrey
11/12/2021, 9:06 AMNElliott
11/12/2021, 9:06 AMSophieGadrey
11/12/2021, 9:17 AMCD
11/12/2021, 9:43 AMSophieGadrey
11/12/2021, 9:45 AMCD
11/12/2021, 9:46 AMSophieGadrey
11/12/2021, 9:48 AMSophieGadrey
11/12/2021, 9:49 AMNElliott
11/12/2021, 9:57 AMbattk
11/12/2021, 7:22 PMbattk
11/12/2021, 7:22 PMbattk
11/12/2021, 7:23 PMbattk
11/12/2021, 7:23 PMSophieGadrey
11/15/2021, 8:43 AMbattk
11/15/2021, 8:44 AMSophieGadrey
11/15/2021, 8:45 AMSophieGadrey
11/15/2021, 8:45 AMbattk
11/15/2021, 8:45 AMbattk
11/15/2021, 8:47 AMSophieGadrey
11/15/2021, 8:48 AMbattk
11/15/2021, 8:49 AMbattk
11/15/2021, 8:50 AM