Netsuite returns this error

When I run this code in netsuite, it returns this error

org.mozilla.javascript.EcmaError: TypeError: Cannot call method “getValue” of undefined (/SuiteScripts/altera_data_ue.js#23)

 

/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
define([‘N/record’], function (record) {
  function beforeLoad(context) {
  }
  function beforeSubmit(context) {
  }
  function afterSubmit(context) {
    // carregar registro
    var curRec = context.currentRecord;
    //pega a data de vencimento atual
    var transDueDate = curRec.getValue({
      fieldId: ‘duedate’
    });
    //pega a condição de pagamento
    var transTerms = curRec.getValue({
      fieldId: ‘terms’
    });
    //string vazia que mantém o campo terms como um número de dias
    var addtlDays;
    //transforma o campo terms em um número de dias
    switch (transTerms) {
      case 1:
        //Ex: 1 = id terms “Net 15”
        addtlDays = 15;
        break;
      case 2:
        // Ex: 2 = id terms “Net 30”
        addtlDays = 30;
        break;
      // adicione declarações de caso adicionais conforme necessário
      default:
        addtlDays = 0;
    }
    //calcula a nova data de vencimento
    var d = new Date(transDueDate);
    var newDueDate = d.setDate(d.getDate() + addtlDays);
    //define a nova data de vencimento
    curRec.setValue({
      fieldId: ‘duedate’,
      value: newDueDate,
      ignoreFieldChange: true
      // opcional, o padrão é falso
    });
  }
  return {
    beforeLoad: beforeLoad,
    beforeSubmit: beforeSubmit,
    afterSubmit: afterSubmit
  }
});
Rookie Asked on August 2, 2021 in SuiteScript.
Add Comment
1 Answer(s)

In a User Event Script, you need:


var curRec = context.newRecord;

Intermediate Answered on August 3, 2021.

Hi, Chris

I changed the code, but netsuite still returns this warning.

I don’t know what the error is

🙁

on August 3, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor