This topic contains 3 replies, has 0 voices, and was last updated by markrCMD7 8 years, 4 months ago.

  • Author
    Posts
  • #2651

    markrCMD7

    So I’ve run into some issues trying to fill a DateTime field with a value. I’m working with a standardized incoming email that I’m parsing up and the section of the email that I’m worried about for this field is formatted like this “Aug 9 2016 9:48AM EDT”

    So then I go through a few js back flips to get that formatted into what NS shows as their preferred format for the nlapiSetDateTimeValue function so by the time I perform that function it looks like this “08/09/2016 09:48:00 AM” (I’m also setting the time zone piece to the appropriate Olson value 14 in this case)

    My issue is that despite the formatting, after the save record nothing shows up in that field. I don’t get any errors telling me that something went wrong, the field just doesn’t get written.

    Can anyone help me figure out what I’m doing wrong?

    The SetDateTimeValue piece looks like this

    Code:
    nlapiSetDateTimeValue(‘myDateTime_field_internal_id’, myDateToSet.FormattedString, myDateToSet.TimeZone);
    Where

    myDateToSet.FormattedString = “08/09/2016 09:48:00 AM”

    myDateToSet.TimeZone = 7

    Thanks in advance for any help I really need to figure this out, I don’t want to turn this into a text field but I will that’s what it comes to.

    Edit – Additional thoughts

    How does nlapiSetDateTimeValue know which record it’s operating on? It’s not a function of objRecord and can’t be called using objRecord.nlapiSetDateTimeValue yet it needs an internal id for a field that will be associated with a record. When running the debugger I’m noticing that the objRecord contains {string} types and {number} types but I don’t see any {date} or {datetime} types, it should contain 2 {datetime} type fields. Grrr WHAT am I missing?

    Edit – Answer

    So those additional thoughts got me thinking and I started to quickly realize that nlapiSetDateTimeValue is not setting the field so the language SET is what was throwing me off here, it’s meant specifically to ADJUST the timezone of a datetime that’s all. I just added a objRecord.setFieldValue call after setting things the way that I needed and I was good to go.

    Guh what a headache haha, I appreciate the scale of what NetSuite is doing but I wish they had better documentation on all of it, so far it’s been one major word game after another.
    This is a cached copy. Click here to see the original post.

  • #2652

    david.smith

    I’ve always had issues with the datetime fields in NetSuite so I avoid them when designing anything new.

    That said, your code looks to be OK. I would change the field and store it as a UTC in the milliseconds format or split it into 2 fields (date & time separate).

  • #2653

    girieshg

    markrCMD7 use the string to date API – nlapiStringToDate() – and set the field value using this APIs output

    Code:
    nlapiSetDateTimeValue(‘myDateTime_field_internal_id’, nlapiStringToDate(myDateToSet.FormattedString), myDateToSet.TimeZone);

  • #2654

    markrCMD7

    girieshg I actually tried that in the beginning and I got invalid format errors because the format that nlapiSetDateTimeValue uses requires leading zeros in the date format and nlapiStringToDate returns a date that looks like (using my example from above) “8/9/2016 09:48” so that didn’t work out. I have a ticket in with NS right now to see if they can help too. I appreciate all the feedback.

You must be logged in to reply to this topic.