I am trying to archive the following
IF the lineitem,"custcol_celigo_sfnc_line_id"field matches the value "01t0g00000bx4WDAAY",then add date.
Here i am facing the issue,This record is triggering 2 times instead of one.
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/record', 'N/search', 'N/url', 'N/https', 'N/runtime'], function(record, search, url, https, runtime) {
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var sublistName = context.sublistId;
var sublistFieldName = context.fieldId;
// alert(JSON.stringify(currentRecord));
//alert(JSON.stringify(context));
var line = context.line;
var start_Date="custcol_atlas_contract_start_date";
var end_date="custcol_atlas_contract_end_date";
if (sublistName === 'item') {
if (sublistFieldName === 'custcol_celigo_sfnc_line_id')
{
var value = currentRecord.getCurrentSublistValue({
sublistId: sublistName,
fieldId: sublistFieldName
})
if(value!="01t0g00000bx4WDAAY"||value!="01t70000004b5TWAAY"||value!="01t70000004b6LZAAY"||value!="01t0g00000Z9ryHAAR"||value!="01t0g00000Z9ryCAAR"||value!="01t0g00000aYySFAA0"||value!="01t0g00000aZJyRAAW")
{
if(value=="01t0g00000bx4WDAAY")
{
// alert("Triggered");
var stdate = currentRecord.getCurrentSublistValue({
sublistId: sublistName,
fieldId: start_Date
})
var newDate = new Date(stdate.setMonth(stdate.getMonth()+1));
currentRecord.setCurrentSublistValue({
sublistId: sublistName,
fieldId: start_Date,
value: newDate
});
}
}
}
}
return true;
}
var exports = {};
exports.fieldChanged = fieldChanged;
return exports;
});
This script is triggering 2 times, so its adding double. How to make it to trigger one time?
Thanks in advance
I don't think the script can trigger twice. Are you getting the "Triggered" alert twice?
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/record', 'N/search', 'N/url', 'N/https', 'N/runtime'], function(record, search, url, https, runtime) {
function fieldChanged(context) {
var currentRecord = context.currentRecord;
var sublistName = context.sublistId;
var sublistFieldName = context.fieldId;
// alert(JSON.stringify(currentRecord));
//alert(JSON.stringify(context));
var line = context.line;
var start_Date="custcol_atlas_contract_start_date";
var end_date="custcol_atlas_contract_end_date";
if (sublistName === 'item') {
if (sublistFieldName === 'custcol_celigo_sfnc_line_id')
{
var value = currentRecord.getCurrentSublistValue({
sublistId: sublistName,
fieldId: sublistFieldName
})
if(value!="01t0g00000bx4WDAAY"||value!="01t70000004b5TWAAY"||value!="01t70000004b6LZAAY"||value!="01t0g00000Z9ryHAAR"||value!="01t0g00000Z9ryCAAR"||value!="01t0g00000aYySFAA0"||value!="01t0g00000aZJyRAAW")
{
if(value=="01t0g00000bx4WDAAY")
{
// alert("Triggered");
var stdate = currentRecord.getCurrentSublistValue({
sublistId: sublistName,
fieldId: start_Date
})
var newDate = new Date(stdate.setMonth(stdate.getMonth()));
currentRecord.setCurrentSublistValue({
sublistId: sublistName,
fieldId: start_Date,
value: newDate
});
}
}
}
}
return true;
}
var exports = {};
exports.fieldChanged = fieldChanged;
return exports;
});
Try the above code once. Let me know the updates in comments below.