如何在suitescript 2.0中通过UE从员工记录中生成一条自定义记录?

问题描述 投票:0回答:1

我需要在创建新的员工记录后,在后台生成一条自定义记录。record.transform(options) 我试着这样做,但到目前为止什么都没有发生,我不知道该在 "我 "中加入什么。toTyperecord.transform obj,因为我的记录不标准.根据你的经验,请你提出一个解决方案.谢谢.

我的代码。

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
1个回答
1
投票

record.transform用于基于其他记录的特定记录,比如生成一个销售订单,基于一个估算记录。

你需要创建你的自定义记录。

var custRec= record.create({
       type: 'customrecord_mxp_payroll',
});

然后你需要在你的记录中填入所需的值。我假设你会使用雇员记录上的一些值吗? 那就做这样的事情。

var nsrecord = record.load({
        type: record.Type.EMPLOYEE,
        id: req.parameters.id
    });
var empValue = nsrecord.getValue('fieldname');
custRec.setValue('fieldname', empValue);
custRec.save();

我希望这能帮到你

© www.soinside.com 2019 - 2024. All rights reserved.