【问题标题】:SuiteScript 2.0 setValue not allowed in the current subrecord (Sales Order Record)当前子记录(销售订单记录)中不允许使用 SuiteScript 2.0 setValue
【发布时间】:2019-02-13 06:41:29
【问题描述】:

我正在尝试为子列表“billingaddress/shippingaddress”设置一个值。但脚本失败,出现错误“当前子记录中不允许设置值”。但是,我能够获得子记录值。

我需要在 SALES ORDER 记录(客户端脚本)上实现以下 suitescript 1.0 到 2.0。

nlapiSetFieldValue('billcity', "TEST");

我在下面尝试过。

 var currentRecordata = currentRecord.get();
 var subrec = currentRecordata.getSubrecord({
    fieldId: 'billingaddress'
  });    

  subrec.setValue({
    fieldId: 'city',
    value:"TEST"
  });

请帮我解决这个问题。

【问题讨论】:

    标签: netsuite suitescript2.0


    【解决方案1】:

    var currentRecordata = currentRecord.get();

    这里,currentRecordata 是一个ReadOnlyRecord,即currentRecord.get() 返回只读记录,因此您无法对其进行更改。

    正如您所说,您正在对客户端脚本进行更改,您希望哪个入口点(方法)进行所述更改?您可以在每个入口点获取记录对象,该对象可用于读写。

    例如。如果你使用pageInit,你会在scriptContext中获得currentRecord,它是由NetSuite自己传递的,你不必使用currentRecord.get();

    此外,如果您想在查看模式下进行更改,则必须使用N/record 模块来加载记录,进行更改然后保存。

    有关client-script 入口点和CurrentRecord 模块的进一步说明,请查看此处。

    【讨论】:

    • 感谢您的回复。我正在使用入口点“beforeLoad”。您能否告诉我如何在不使用“currentRecord.get();”的情况下更新当前记录。此外,更改是否会在不加载页面的情况下立即反映在 UI 中?
    • ClientScript 中没有 beforeLoad。如果您只想在编辑模式下更新记录,您可以使用客户端脚本的pageInit 方法,您将在脚本上下文中获取 currentRecord。我认为 NetSuite 不允许在 beforeLoad 中提交记录,因为这会导致 Record Has Been Changed 错误
    • 至于反映更改,是的,如果您在 pageInit 中进行任何编辑,它将立即反映在 UI 上,尽管您应该在 ClientScript 的 saveRecord 或 UserEvent 中的 beforeSubmit 中进行更改
    • 根据我的要求,我需要在现有的销售订单表格上添加一个按钮,然后单击按钮更新现有的帐单/送货地址。我在 UserEventScript 下面使用在“beforeLoad”上添加按钮 if (context.type == context.UserEventType.EDIT || context.type == context.UserEventType.VIEW) { context.form.clientScriptModulePath = './clientScripts.js' ; context.form.addButton({ id: 'custpage_btn', label: '我的按钮', functionName: 'validate' }); }
    • clientScripts.js - 代码:函数 validate () { try { var currentRecordata = currentRecord.get(); var subrec = currentRecordata.getSubrecord({ fieldId: 'billingaddress' }); var cityValue = subrec.getValue({ fieldId: 'city' }); subrec.setValue({ fieldId: 'city' value: "Test" }); } 捕捉 (e) { console.log(JSON.stringify(e)); } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多