【问题标题】:How to generate a custom record from employee record, through UE in suitescript 2.0?如何通过suitescript 2.0中的UE从员工记录生成自定义记录?
【发布时间】: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


    【解决方案1】:

    record.transform 用于基于其他记录的特定记录,例如基于 Estimate 记录生成销售订单。

    您需要创建自定义记录:

    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();
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多