Hi, the following code gives me this warning in ne...
# suitescript
s
Hi, the following code gives me this warning in netsuite: Invalid date value(must be DD/MM/YYY)
define(['N/record'], function (record) {
  
function beforeLoad(context) {
  
}
  
function beforeSubmit(context) {
  
}
  
function afterSubmit(context) {
    
// carregar registro
    
var curRec = context.newRecord;
    
//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
  
}
});
s
Couple of things... dates are a pain, in general you should be using
N/format
before setting them... second, Date.setDate() modifies the original date object and returns void, so newDueDate might not be what you expect... third I would recommend using a js date library to modify/deal with dates, and set fields with setText after turning the date into a string with the local users date preference (using
N/runtime
to get this)
😄 1
b
im giving the opposite advice, you dont need N/format here
😄 1
set your date field with a Date value instead of a number
😂 1
😄 1