亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SuiteScript 2.0 TypeError 無法調用未定義的方法“getValue”

SuiteScript 2.0 TypeError 無法調用未定義的方法“getValue”

藍山帝景 2024-01-18 15:47:50
我正在嘗試使用下面的代碼從兩個交易正文字段獲取值。/** *@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” ”我在這里做錯了什么?
查看完整描述

3 回答

?
瀟湘沐

TA貢獻1816條經驗 獲得超6個贊

傳遞到用戶事件中沒有currentRecord屬性,因此錯誤消息告訴您該屬性未定義。查看入口點的文檔以找到適當的值。contextrecordbeforeSubmit



查看完整回答
反對 回復 2024-01-18
?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

在 SuiteScript 2 上,每個入口點都有不同的參數,因此您需要在幫助中檢查這些參數,或者如果您使用 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

 */

然后您可以看到 context 參數沒有 currentRecord 屬性,而是有兩個其他參數,您可以使用newRecord或oldRecord,因此您的代碼可以如下所示:


/**

 *@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,

    

    };

});


查看完整回答
反對 回復 2024-01-18
?
波斯汪

TA貢獻1811條經驗 獲得超4個贊

你試試這樣寫,我都是用這個方法來獲取字段值。

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


查看完整回答
反對 回復 2024-01-18
  • 3 回答
  • 0 關注
  • 226 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號