This topic contains 2 replies, has 0 voices, and was last updated by mbouchard 7 years, 11 months ago.

  • Author
    Posts
  • #6122 Score: 0

    mbouchard
    • Contributions: 0
    • Level 1

    I’m trying to set a DateTime field using the setDateTimeValue method. It works fine when the user’s preferences for date format is mm/dd/yyyy and time format is hh:mm AM/PM, but if the user executing the script has any other formats picked in their preferences (i.e. 24 hour time format for example) it does not appear to work – an invalid argument error is returned. I’ve tried making sure that the same format is always entered to the method, and I’ve also tried matching the format to the user’s preferences but it does not seem to matter. Does anyone have a trick, suggestion or confirmation that it is a bug?

    example:

    var caseRec = nlapiLoadRecord(‘supportcase’,caseId);

    soRec.setDateTimeValue(‘custevent_early_eta_dt_crm ‘,’10/06/2016 10:00:00 am’,5);

    This works fine with the user preferences set for m/d/yyyy hh:mm am/pm, but as soon as you change your preferences to anything else it yields:
    You have entered an Invalid Field Value 10/06/2016 10:00:00 am for the following field: custevent_early_eta_dt_crm

    Thanks!

    Mike
    This is a cached copy. Click here to see the original post.

  • #6123 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    You need to use both nlapiStringToDate and nlapiDateToString. The first will give you a date object and the second uses the user’s preference format to set the date field.

  • #6124 Score: 0

    mbouchard
    • Contributions: 0
    • Level 1

    Thanks David, I see that does indeed allow it to work without error. That makes it a little tricky for my application due to timezones unfortunately, but I’ll come up with a way to work through that.

    Thanks again,

    Mike


    david.smith replied on 10/05/2016, 02:06 PM: you can use datetimetz as one of the parameters.

You must be logged in to reply to this topic.