我有一个suitescript,应该检查一个框,然后在创建新发票或更新旧发票时创建日志条目。但是,在导入包含我想要更新的发票的csv文件时,它只选中复选框,而不创建适当的日记账分录。我已经在"导入CSV偏好"中检查了"运行服务器SuiteScript和触发工作流",并做了我能想到的一切,我仍然卡住了。任何帮助都是受欢迎的。您可以在下面找到脚本:
/* ** @NApiVersion 2.1* @NScriptType UserEventScript*/
定义("N/记录",函数(记录){
function afterSubmit(context){
let invoice = context.newRecord;
let uk_subs = [11,13,14,12,38,39,42,52,54,55,56,57,58,53,46,16,41,18]
let esp_subs = [47,7,48,5,4,45,3,6,9,10,40]
let invoice_subs = parseInt(invoice.getValue('subsidiary'));
let link_anacap = invoice.getValue('custbodyfinaced_anacap_jt');
let link_journal = invoice.getValue('custbody_journal_created')
let invoice_num = invoice.getValue('tranid')
let total_amount = invoice.getValue('custbody_stc_total_after_discount');
function create_journal(object, account_1, account_2, account_3){
object.selectNewLine('line');
object.setCurrentSublistValue('line','account',account_1);
object.setCurrentSublistValue('line','credit',total_amount);
object.commitLine('line');
object.selectNewLine('line');
object.setCurrentSublistValue('line','account',account_2);
object.setCurrentSublistValue('line', 'debit',total_amount*0.02);
object.commitLine('line');
object.selectNewLine('line');
object.setCurrentSublistValue('line','account',account_3);
object.setCurrentSublistValue('line', 'debit',total_amount *0.98);
object.commitLine('line');
return object.save();
}
if(context.type == context.UserEventType.CREATE || context.type == context.UserEventType.EDIT){
if(link_anacap == true && link_journal== false){
/* record.submitFields({
id: context.newRecord.id,
type: context.newRecord.type,
values:{'custbody_journal_created':true}
}); */
let create_jour = record.create({
type: record.Type.JOURNAL_ENTRY,
isDynamic : true
});
create_jour.setValue('subsidiary', invoice_subs);
create_jour.setValue('memo', invoice_num);
record.submitFields({
id: context.newRecord.id,
type: context.newRecord.type,
values:{'custbody_journal_created':true}
});
if(esp_subs.includes(invoice_subs)){
create_journal(create_jour, 1027,1008,5919)
}
else if(uk_subs.includes(invoice_subs)){
create_journal(create_jour,1022, 1008, 7586)
}
}
} else if(link_anacap == true && link_journal== true){}
}
进入正在创建JEs的脚本的脚本部署记录
在"上下文过滤"选项卡上,有一个"执行上下文"字段。确保选择"CSV Import"上下文。