【发布时间】:2020-03-03 06:38:46
【问题描述】:
创建新员工记录后,我需要在后端生成自定义记录,我只是想知道record.transform(options) 是否是正确的选择。
我试过这样做,但到目前为止什么都没有发生,我不知道在record.transform obj 的toType 属性中放入什么,因为我的记录不标准。
请根据您的经验提出解决方案。谢谢
我的代码:
define(['N/record', 'N/ui/serverWidget', '../library/global_constants.js'], function (record, ui, globalConstants) {
function afterSubmit(context) {
if (type == ctx.UserEventType.CREATE || type == ctx.UserEventType.EDIT) {
createPayrollRec(context);
}
}
function createPayrollRec(ctx) {
try {
var rec = ctx.newRecord;
var form = ctx.form;
var hireDate = rec.getValue({ fieldId: 'hiredate' });
var childRecLen = rec.getLineCount({ sublistId: 'here_will_come_payroll_child' });
if (!!hireDate && childRecLen > 0) {// if hireDate field is populated and chidlRec has lines
var tranfRec = rec.transform({
fromType: rec.Type.EMPLOYEE,
fromId: req.parameters.id,
toType: 'customrecord_mxp_payroll',// this is my custom rec id
isDynamic: true,
});
log.debug('tranfRec', tranfRec);
tranfRec.save({
ignoreMandatoryFields: true
});
log.debug('Payroll Record Created!');
}
} catch (error) {
log.error('Error: on afterSubmit', error)
}
}
return {
afterSubmit: afterSubmit
}
});
【问题讨论】:
标签: suitescript suitescript2.0