Slig
08/03/2021, 1:45 PMdefine(['N/record'], function (record) {
function beforeLoad(context) {
}
function beforeSubmit(context) {
}
function afterSubmit(context) {
// carregar registro
var curRec = context.newRecord;
//pega a data de vencimento atual
var transDueDate = curRec.getValue({
fieldId: 'duedate'
});
//pega a condição de pagamento
var transTerms = curRec.getValue({
fieldId: 'terms'
});
//string vazia que mantém o campo terms como um número de dias
var addtlDays;
//transforma o campo terms em um número de dias
switch (transTerms) {
case 1:
//Ex: 1 = id terms "Net 15"
addtlDays = 15;
break;
case 2:
// Ex: 2 = id terms "Net 30"
addtlDays = 30;
break;
// adicione declarações de caso adicionais conforme necessário
default:
addtlDays = 0;
}
//calcula a nova data de vencimento
var d = new Date(transDueDate);
var newDueDate = d.setDate(d.getDate() + addtlDays);
//define a nova data de vencimento
curRec.setValue({
fieldId: 'duedate',
value: newDueDate,
ignoreFieldChange: true
// opcional, o padrão é falso
});
}
return {
beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit,
afterSubmit: afterSubmit
}
});
Sandii
08/03/2021, 2:21 PMN/format
before setting them... second, Date.setDate() modifies the original date object and returns void, so newDueDate might not be what you expect... third I would recommend using a js date library to modify/deal with dates, and set fields with setText after turning the date into a string with the local users date preference (using N/runtime
to get this)battk
08/03/2021, 2:22 PMbattk
08/03/2021, 2:22 PM