<@U0290MVCVPC> The line with `var newDueDate = d.s...
# suitescript
s
@Slig The line with
var newDueDate = d.setDate(d.getDate() + addtlDays);
could be the issue.
Date.setDate
does not return a new Date, it modifies the Date object it is called on. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate for reference.
😄 1
👆 1
s
Hey @scottvonduhn In this case, I want the date to extend according to a condition existing in one in the terms field, as it is in the code. He understands?
And this condition is different for some companies. He understands?
s
Rephrasing: I assume you want to extend the date by a certain number of days according to the payment terms? The problem with raw JS date objects is that you'd have to handle the ends of months and years (plus the occasional leap year) yourself. Whenever I have to start modifying dates, I immediately use a library, such as Moment. It will handle the addition of days for you correctly, so you can focus on your script and not have to worry about date manipulation.
😄 1
There are other libraries like date-fns and js-joda that will work similarly. Pick whichever one you like.
😄 1
In short, you can't just add days to a date, for example, adding 15 to July 30 will give you July 45, which is not valid. JavaScript won't figure out the correct new date for you, unfortunately, which is why a date library is very useful for this situation.
😄 1
m
@scottvonduhn you should be able to add days like that with standard Date object, Per the MDN page
If the dayValue is outside of the range of date values for the month, setDate() will update the Date object accordingly.
😄 1
s
Really? That's good to know! I kind of always assumed that it wouldn't work. Very interesting.
😄 1
s
Thanks @michoel, thanks @scottvonduhn
So, let me understand, so I can add the days I have to do this manually? Because some of the payment terms will give different days. For example, some will have 90 days. Others, 120 days. He understands? @scottvonduhn @michoel Sorry for asking. I'm new to NetSuite and I'm struggling to learn :)
s
Well, I assume that this is a transaction record? If so, then you simply need to set the terms on the transaction to match the customer terms. The appropriate # of days should be added to the transaction date to calculate the due date automatically. Have you tried just setting the date and terms to see if the due date gets set correctly? Try not setting the due date at all.
s
I will try. Thanks a lot 😄