在用户事件中使用 nlapiLoadRecord 在加载前阶段返回记录

Returning a record at the before load stage using nlapiLoadRecord in a User Event

我只想在销售订单上的自定义字段已填充时才在销售订单上显示按钮。我有一个用户事件脚本(如下所示)运行 "before load" 来添加按钮。该部分有效,但我希望 nlapiLoadRecord 在 "before load" 阶段 return 记录,以便我可以检查该字段是否已填充。我没有成功 return 记录,我不知道这是否真的可能 [?] 有人可以帮我吗?

function BeforeLoad(type, form) {

  if (type=='view') {
    form.setScript('customscript_instruction_script');
    form.addButton("custpage_mybutton", "Instructions", "instruction_click();");
  }

}

如果您只想从正在加载的实际记录中获取某个字段的值,则无需调用nlapiLoadRecord()。您可以使用 nlapiGetFieldValue():

简单地检索值
if (type=='view') {
  var customFieldValue = nlapiGetFieldValue('custbody_mycustomfield');
  if(customFieldValue === "123") {
    form.setScript('customscript_instruction_script');
    form.addButton("custpage_mybutton", "Instructions", "instruction_click();");
  }
}

但是,如果自定义字段来自不同的记录,您将需要通过加载该记录或运行 搜索来检索它。一般来说 nlapiLookupField() 是最轻量级的选项。