my code is giving an error. What is wrong? {"type...
# suitescript
s
my code is giving an error. What is wrong? {"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["anonymous(N/serverRecordService)","afterSubmit(/SuiteScripts/altera_data_ue.js:47)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":"aftersubmit","stackTrace":["anonymous(N/serverRecordService)","afterSubmit(/SuiteScripts/altera_data_ue.js:47)"],"notifyOff":false},"id":"5979cc9b-22af-4bf2-9484-203d5027284f-2d323032312e30382e3138","notifyOff":false,"userFacing":false}
Copy code
function afterSubmit(context) {
		 //Carrega registro Term
        var objTerm = record.load({
            type: record.Type.TERM,
            id: 193,
            isDynamic: true
        });


      //Carrega registro Fatura
        var objFatura = record.load({
            type: record.Type.INVOICE,
            id: 4952604,
            isDynamic: true
        });

        //ObtΓ©m valor da campo duenextmonthifwithindays que estΓ‘ dentro da fatura Term
      	   var nTerm = objFatura.getValue({
           		fieldId: "duenextmonthifwithindays"
        	});

      	//variavel contendo objeto Date
          //var termsData = new Date();

        //Define valor de duedate com o valor obtido do objeto objTerm
        objFatura.setValue({
            fieldId: "duedate",
            value: nTerm,
            ignoreFieldChange: false
          });

         var recordId = objFatura.save({
        	enableSourcing: false,
            ignoreMandatoryFields: false
      })

      return recordId;
    }
Copy code
Line #47 is this:
 var recordId = objFatura.save({
        	enableSourcing: false,
            ignoreMandatoryFields: false
      })
s
Almost guaranteed to the date, use setText if using a string to set a date field. You can also try parsing the string into a date properly with
N/format
if you want to use setValue
πŸ‘ 1
b
nTerm is a number
πŸ‘ 1
you dont set a date field with a number
πŸ‘ 1
s
@battk Is there any way to define this? Do I have to convert it?
b
have you figure out how to set a duedate yet?
s
This is a date that appears in the field. I'm trying to update it based on the value of this 'duenextmonthifwithindays' field.
@battk
b
You should know how to set the duedate with any value
s
How do I do that?
b
Last time you shared your code you were trying to set it with a string
πŸ‘ 1
This time a number
πŸ‘ 1
The answer is the same as last time, use a Date with setValue
πŸ‘ 1
Or a string with setText
πŸ‘ 1
s
I actually have to set a date, like '10/10/2021', right? Can't use the value of this field to change the duedate?
b
the values you see in netsuite are represented in suitescript different ways
duenextmonthifwithindays is represented as a number
in this case 90
duedate has 2 representations
the string '10/10/2021'
and a date, which is probably somewhere near new Date(1633863600000)
figure out how to set duedate and then you can move onto what you need to do with duenextmonthifwithindays to make it the value you want
s
Anyway, do I have to use a Date with setvalue or a string with setText? For example, do I have to set the same date, like '20/12/2021', with another date?
b
either works, they are both represent the same value in netsuite
πŸ‘ 1
just do not try to use a string with setValue or a Date with setText
πŸ‘ 1
your current attempt with using a number with setValue is not even close
πŸ‘ 1
s
Hey @battk correct me if I'm wrong, but I was looking at the netsuite documentation, in the Record.setValue (options) section, the accepted data types are: number | date | string | array| boolean true | false
I'm using string with in setValue, but in the documentation I hope I'm wrong, it says it's allowed
b
depends on the field type
numbers are for field types like integer or currency
date is for date or date/time
string is for text fields like free form text
array for multi select
boolean is for checkboxes
you will continue to fail if you try to use setValue on a date field with a string
πŸ‘† 2
s
@battk I'm not trying that way. I just wanted some information about it. appreciate