I'm trying to adjust the start time / end time of ...
# suitescript
c
I'm trying to adjust the start time / end time of a task activity using suitescript, based on another custom field. When I run this on the client side (in the console) it works perfectly -- the time in the starttime and endtime fields matches the time in the two custom fields. However, when I run it as part of the user event script, each time is off by 2 hours. I assume it's due to the server being on a different timezone? Can anyone help guide me on how to get the value returned from getValue so it works with starttime? When I run this in the rec = record.load({type: 'task', id: 42492}) START_TIME = rec.getValue('custevent_scheduled_start') END_TIME = rec.getValue('custevent_scheduled_end') rec.setValue("timedevent",true) rec.setValue('starttime', START_TIME) rec.setValue('endtime', END_TIME) rec.save()
Scratch that, I got it working like so:
Copy code
function formatDateTimeCentral(dateObj) {
    return format.format({
        value: dateObj,
        type: format.Type.DATETIME, // <-- DATETIME not DATE
        timezone: format.Timezone.AMERICA_CHICAGO // Central Time
    });
}
Copy code
rec.setValue('starttime',  new Date(formatDateTimeCentral(new Date(START_TIME))))
rec.setValue('endtime',  new Date(formatDateTimeCentral(new Date(END_TIME))))
🫡 1