JIRA CODE : MR-157
Client script for restricting the Duplication in Tracfone Activations custom record. Whenever making an entry into custom record ‘Tracfone Activations’, the value on fields SIM and ESN not repeat. The value should be considered as pairs and be unique. If they repeat it shows an alert message and never allow the user to save the record.
The script only works for the UI edits and it will not work on the Importing purpose.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:MEGATEL
* MR-157
* Restrict Duplication in custom records
*************************************************************************
* Date : 01-03-2019
*
* Author:Jobin and Jismi IT services LLP
* Script Description : Restrict Duplication in custom records
* Date created : 01-03-2019
*
* REVISION HISTORY
*
* Revision 1.0 ${01-03-2019} nd :marg created
*
*
*
******************************************************************************/
define(['N/record','N/search','N/currentRecord'],
function(record,search,currentRecord) {
function saveRecord(scriptContext) {
try{
var records = scriptContext.currentRecord;
log.debug('records',records)
var sim = scriptContext.currentRecord.getValue("custrecordjj_tra_sim");
console.log('sim', sim)
var esn = scriptContext.currentRecord.getValue("custrecord_jj_tra_esn");
console.log('esn', esn)
var tracfoneRecsearch = search.create({
type: "customrecord_jj_tracfone_activations",
filters: [
["custrecordjj_tra_sim", "is",sim ],
"AND",
["custrecord_jj_tra_esn", "is", esn]
],
columns: [
search.createColumn({
name: "custrecordjj_tra_sim",
label: "SIM"
}),
search.createColumn({
name: "custrecord_jj_tra_esn",
label: "ESN"
}),
search.createColumn({
name: "internalid",
label: "Internal ID" })
]
})
var searchResultCount = tracfoneRecsearch.runPaged().count;
console.log("tracfoneRecsearch result count",tracfoneRecsearch);
console.log('searchResultCount', searchResultCount)
if(searchResultCount > 0) {
alert("Record Have Duplicates");
return false;
}
else{
return true;
}
var saverecord = tracfRec.save();
console.log('saverecord', saverecord)
}catch(e){
console.log('error',e.message)
}
}
return {
saveRecord: saveRecord
};
});