Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SuiteScript 2.0 TypeError无法调用方法“;getValue";未定义的_Javascript_Netsuite_Suitescript2.0 - Fatal编程技术网

Javascript SuiteScript 2.0 TypeError无法调用方法“;getValue";未定义的

Javascript SuiteScript 2.0 TypeError无法调用方法“;getValue";未定义的,javascript,netsuite,suitescript2.0,Javascript,Netsuite,Suitescript2.0,我试图使用下面的代码从两个事务体字段中获取值 /** *@NApiVersion 2.x *@NScriptType UserEventScript *@param {Record} context.currentRecord */ define(['N/record'], function (msg) { function beforeSubmit(context) { try { var record = context.curre

我试图使用下面的代码从两个事务体字段中获取值

/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 *@param {Record} context.currentRecord
 */

define(['N/record'], 
function (msg) {
    
    function beforeSubmit(context) {
      try {

        var record = context.currentRecord;               

        var createdDate = record.getValue({
            fieldId: 'createddate'
        });

        var dataNecessidade = record.getValue({
            fieldId: 'custbodyek_data_nece_requ_po'
            
        });

        console.log(createdDate ,dataNecessidade);        

        }
        catch(ex){
        log.error(ex);
        }
    }
    return {
        beforeSubmit : beforeSubmit,
    
    };
});
引发的错误是“TypeError:无法调用未定义的”的方法“getValue”

我做错了什么


谢谢大家!

传递到用户事件的
上下文
上没有
currentRecord
属性,因此错误消息告诉您
记录
未定义。在提交前查看
入口点的文档,以找到合适的值。

如果您尝试这样编写,我总是使用此方法获取字段值

const bfRecord= context.newRecord;
const createdDate = bfRecord.getValue('createddate');

在SuiteScript2上,每个入口点都有不同的参数,因此您需要在帮助中检查这些参数,或者如果您使用Eclipse之类的IDE,则在创建新脚本时将获得这些信息,因此对于UserEvent脚本和beforeSubmit入口点,您将获得如下信息:

/**
 * Function definition to be triggered before record is loaded.
 * 
 * Task #5060 : calculate PO Spent Amount and Balance in realtime
 *
 * @param {Object} scriptContext
 * @param {Record} scriptContext.newRecord - New record
 * @param {Record} scriptContext.oldRecord - Old record
 * @param {string} scriptContext.type - Trigger type
 * @Since 2015.2
 */
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 *@param {Record} context.currentRecord
 */

define(['N/record'], 
function (msg) {
    // are you aware that you are "injecting" the 'N/record' library into the 'msg' variable ???
    function beforeSubmit(context) {
      try {

        var record = context.newRecord;               

        var createdDate = record.getValue({
            fieldId: 'createddate'
        });

        var dataNecessidade = record.getValue({
            fieldId: 'custbodyek_data_nece_requ_po'
            
        });

        console.log(createdDate ,dataNecessidade);        

        }
        catch(ex){
        log.error(ex);
        }
    }
    return {
        beforeSubmit : beforeSubmit,
    
    };
});
然后您可以看到上下文参数没有currentRecord属性,相反,它有两个其他参数,您可以使用newRecord或oldRecord,因此您的代码可以如下所示:

/**
 * Function definition to be triggered before record is loaded.
 * 
 * Task #5060 : calculate PO Spent Amount and Balance in realtime
 *
 * @param {Object} scriptContext
 * @param {Record} scriptContext.newRecord - New record
 * @param {Record} scriptContext.oldRecord - Old record
 * @param {string} scriptContext.type - Trigger type
 * @Since 2015.2
 */
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 *@param {Record} context.currentRecord
 */

define(['N/record'], 
function (msg) {
    // are you aware that you are "injecting" the 'N/record' library into the 'msg' variable ???
    function beforeSubmit(context) {
      try {

        var record = context.newRecord;               

        var createdDate = record.getValue({
            fieldId: 'createddate'
        });

        var dataNecessidade = record.getValue({
            fieldId: 'custbodyek_data_nece_requ_po'
            
        });

        console.log(createdDate ,dataNecessidade);        

        }
        catch(ex){
        log.error(ex);
        }
    }
    return {
        beforeSubmit : beforeSubmit,
    
    };
});

嗨,阿萨姆!谢谢你的贡献!实际上,我使用的是VS代码。有没有办法像EclipseIDE一样获得这些参数?非常感谢。嗨@eklon我从来没有使用过Netsuite定制的VS代码,所以很抱歉,在这方面我帮不了你。