我正在尝试在SuiteScript 2.0中创建客户存款。我在将帐户存入客户存款时遇到麻烦。
function createCustomerDeposit(data){
var record = data.modules.record;
var salesorder = data.salesorder.id;
var customerid = data.customerid;
var transactionid = data.transactionid;
var payment_amount = data.payment_amount;
var accountREC = record.load({
type : record.Type.ACCOUNT,
id : 145
});
var customerDepositREC = record.create({
type : record.Type.CUSTOMER_DEPOSIT
}).setValue({
fieldId : 'entity',
value : customerid
}).setValue({
fieldId : 'salesorder',
value : salesorder
}).setValue({
fieldId : 'payment',
value : payment_amount
}).setValue({
fieldId : 'undepfunds',
value : 'F'
}).setValue({
fieldId : 'account',
value : accountREC
}).setValue({
fieldId : 'memo',
value : transactionid
}).save({
ignoreMandatoryFields : true
});
}
ID 145是我想要的帐户的ID。我可以确认它正在为accountREC加载正确的帐户。但是,当我尝试保存此客户存款时不起作用。请帮忙。
答案 0 :(得分:0)
问题出在客户存款的初始化中。创建CD时,我无需尝试设置account和salesorder字段,而是需要使用defaultValues参数。
function createCustomerDeposit(data){
var record = data.modules.record;
var salesorder = data.salesorder;
var customerid = data.customerid;
var transactionid = data.transactionid;
var payment_amount = data.payment_amount;
var accountREC = record.load({
type : record.Type.ACCOUNT,
id : 145
});
var customerDepositREC = record.create({
type : record.Type.CUSTOMER_DEPOSIT,
defaultValues: {
entity: customerid,
salesorder: salesorder.id,
}
});
customerDepositREC.setValue({
fieldId : 'paymentmethod',
value : PAYMENT_METHOD_DIRECT_DEPOSIT
});
customerDepositREC.setValue({
fieldId : 'payment',
value : payment_amount
});
customerDepositREC.setValue({
fieldId : 'memo',
value : transactionid
});
customerDepositREC.setValue({
fieldId : 'undepfunds',
value : 'F'
});
customerDepositREC.setValue({
fieldId : 'account',
value : accountREC.id
});
customerDepositREC.save();
}