ReferenceError-未定义上下文(Netsuite)

时间:2019-06-12 13:44:21

标签: netsuite

在“机会”中选中一个复选框后,我试图隐藏一个字段,但是我拥有的脚本抛出了ReferenceError - Context is not defined

这是我的代码:

define(['N/currentRecord','N/search', 'N/format'],

function(currentRecord, search, format) {
  function pageInit_disableMyText(scriptContext) {
    console.log('START : here you will be able see logs via console (F12 on browser)');

    var recCurrent = context.currentRecord; //This represents your current loaded record, you can get the values of the fields here

    var myCheckbox = recCurrent.getValue('custbody7'); //This is the code for getting the value of your field
    console.log('myCheckbox Value is : ' + myCheckbox);

    if(myCheckbox == true)
    {
        //get the field and disable it
        fld1 = recCurrent.getField('custbody3');
        fld1.isDisabled = true;
    }
    else
    {
        //if you didn't set the field to be disabled by default, then you don't need the code to enable it here
        //since it runs only once when the page loads
    }
  }

  function fieldChanged_toggleBox(scriptContext) {

    //Different function that triggers on change of a field value, can use this to toggle the checkbox
    var currentFieldID = context.fieldId;

    console.log('context.fieldId : '+ currentFieldID);
    //Check which field is toggled
    if(currentFieldID == 'custbody7')
    {
        //Essentially do the same as above
        var recCurrent = context.currentRecord;
        var myCheckbox = recCurrent.getValue('custbody7');
        if(myCheckbox == true)
        {
            //get the field and disable it
            fld1 = recCurrent.getField('custbody3');
            fld1.isDisabled = true;
        }
        else
        {
            //Now you need code to enable it as you are toggling the disabling and enabling it realtime
            fld1 = recCurrent.getField('custbody3');
            fld1.isDisabled = false;
        }
    }
  }


  //this is the retrun statement where we declare the script type to implement
  return {
    pageInit: pageInit_disableMyText,
    fieldChanged: fieldChanged_toggleBox
  };

});

当我在Chrome中使用devtools时,此行显示错误:

    var recCurrent = context.currentRecord; //This represents your current loaded record, you can get the values of the fields here

但是我看不出是什么问题。

感谢您的帮助。

谢谢!

1 个答案:

答案 0 :(得分:3)

函数中的参数名称为 scriptContext ,将其更改为context

function pageInit_disableMyText(scriptContext) { // <---- Change this parameter to context

基本上,您可以随意调用它,但随后必须使用相同的变量。