根据terms字段的值填充数据字段



是否可以根据terms字段填充duedate字段?例如,我在duedate字段中有一个日期,但我想根据terms字段扩展它。我该怎么做呢?通过脚本还是工作流?

代码不完整,因为我不知道我是否在正确的路径上。(注:这是一个用户事件)

function beforeLoad(context) {

}
function beforeSubmit(context) {

}
function afterSubmit(context) {
var dataEntrega = context.currentRecord
currentRecordRecord.getValue({
fieldId: 'duedate'
})
var dataCondicoes = context.currentRecord
currentRecord.getValue({
fieldId: 'terms'
})

}
return {
beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit,
afterSubmit: afterSubmit
}

为什么需要编写这个脚本?我相信到期日是根据开箱即用的条款计算的,不需要编写脚本

下面的代码应该可以工作。根据您的需要,我建议在执行此逻辑时添加一些限制。例如,您只能根据事务/记录模式是创建/复制来执行(决定是否要包含编辑)。您还可以检查事务的状态,并且仅在状态不是部分支付/全部支付时执行…

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);
//set the new due date
curRec.setValue({
fieldId: 'duedate',
value: newDueDate,
ignoreFieldChange: true //optional, default is false
});
}

最新更新