Slig
08/04/2021, 7:20 PMvar d = new Date(transDueDate);
var newDueDate = d.setDate(d.getDate() + transTerms);
var newAcceptableDate = format.format({
value: newDueDate,
type: format.Type.DATE
})
curRec.setValue({
fieldId: 'duedate',
value: newAcceptableDate,
ignoreFieldChange: true
// opcional, o padrão é falso
});
Bibek Shrestha
08/04/2021, 7:22 PMdefine(["N/record", "N/render", "N/format]
Slig
08/04/2021, 7:26 PMbattk
08/04/2021, 8:14 PMbattk
08/04/2021, 8:14 PMSlig
08/05/2021, 1:52 PMSlig
08/05/2021, 1:53 PMbattk
08/05/2021, 5:28 PMSlig
08/05/2021, 5:32 PMSlig
08/05/2021, 5:32 PMbattk
08/05/2021, 5:37 PMbattk
08/05/2021, 5:38 PMSlig
08/05/2021, 5:40 PM/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define(['N/record', 'N/format', 'N/render'], function (record, format, render) {
function beforeLoad(context) {
}
function beforeSubmit(context) {
}
function afterSubmit(context) {
//load record
var curRec = context.newRecord; //can substitute "context.oldRecord", or "currentRecord.get();"
//get current due date
var transDueDate = curRec.getValue({fieldId: 'duedate'});
//get the terms, this will likely come as an internal id. use getText if you want the text.
var transTerms = curRec.getValue({fieldId: 'terms'});
//empty string to hold terms as a number of days
var addtlDays;
//transform the internal id to terms as a number of days
switch (transTerms){
case 1: // Ex: 1 = internal id for term "Net 15"
addtlDays = 15;
break;
case 2: // Ex: 2 = internal id for term "Net 30"
addtlDays = 30;
break;
//add additional case statements as needed
default:
addtlDays = 0;
}
//calculuate the new due date
var d = new Date(transDueDate);
var newDueDate = d.setDate(d.getDate() + addtlDays);
var NewAcceptableDate = format.format({
value: newDueDate,
type: format.Type.DATE
})
//set the new due date
curRec.setValue({
fieldId: 'duedate',
value: newAccept,
ignoreFieldChange: true //optional, default is false
});
}
return {
beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit,
afterSubmit: afterSubmit
}
});
Slig
08/05/2021, 5:40 PMSlig
08/05/2021, 5:41 PMbattk
08/05/2021, 5:43 PMSlig
08/05/2021, 5:44 PMbattk
08/05/2021, 5:44 PMbattk
08/05/2021, 5:45 PMbattk
08/05/2021, 5:45 PMbattk
08/05/2021, 5:47 PMbattk
08/05/2021, 5:49 PMbattk
08/05/2021, 5:51 PMSlig
08/05/2021, 5:52 PMbattk
08/05/2021, 5:52 PMSlig
08/05/2021, 5:53 PMSlig
08/05/2021, 5:53 PMbattk
08/05/2021, 5:54 PMbattk
08/05/2021, 5:56 PMbattk
08/05/2021, 5:58 PMbattk
08/05/2021, 5:58 PMSlig
08/05/2021, 7:12 PMSlig
08/05/2021, 7:12 PMbattk
08/05/2021, 7:15 PMbattk
08/05/2021, 7:16 PMbattk
08/05/2021, 7:17 PMSlig
08/05/2021, 7:20 PMbattk
08/05/2021, 7:23 PMbattk
08/05/2021, 7:24 PMbattk
08/05/2021, 7:25 PMSlig
08/05/2021, 7:31 PMbattk
08/05/2021, 7:34 PMbattk
08/05/2021, 7:34 PMSlig
08/05/2021, 7:35 PMSlig
08/05/2021, 7:37 PMSlig
08/05/2021, 7:38 PMbattk
08/05/2021, 7:40 PMbattk
08/05/2021, 7:40 PMbattk
08/05/2021, 7:40 PMSlig
08/05/2021, 7:41 PM