Vishal Chaudhari
05/30/2025, 5:31 AM/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/record', 'N/log', 'N/ui/serverWidget','N/format'], function(record, log, serverWidget,format) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({ title: 'Create Test Meeting' });
form.addSubmitButton({ label: 'Create Meeting' });
context.response.writePage(form);
} else if (context.request.method === 'POST') {
try {
var hardcodedMeeting = {
Title: "Test Meeting from Suitelet",
Notes: "This meeting is created by a Suitelet with hardcoded data.",
Date: "05/29/2025", // MM/DD/YYYY
StartTime: "11:00", // HH:mm (24-hour)
EndTime: "11:30", // HH:mm
Status: "CONFIRMED",
Organizer: 50004,
CustomerId: 49691,
};
// Combine date and time into full datetime strings
var startDateTimeString = hardcodedMeeting.Date + ' ' + hardcodedMeeting.StartTime;
var endDateTimeString = hardcodedMeeting.Date + ' ' + hardcodedMeeting.EndTime;
// Parse into full Date objects
var startDateTime = new Date(startDateTimeString);
var endDateTime = new Date(endDateTimeString);
// Create the calendar event
var event = record.create({
type: record.Type.CALENDAR_EVENT,
isDynamic: true
});
// 1. Parse date only
var dateOnly = format.parse({
value: '29/5/2025',
type: format.Type.DATE
});
// 2. Parse start and end times (time of day only)
var startTime = format.parse({
value: '10:00 am',
type: format.Type.TIMEOFDAY
});
var endTime = format.parse({
value: '11:00 am',
type: format.Type.TIMEOFDAY
});
event.setValue({ fieldId: 'title', value: hardcodedMeeting.Title });
event.setValue({ fieldId: 'message', value: hardcodedMeeting.Notes });
event.setValue({ fieldId: 'startdate', value: new Date('2023-02-28T08:00:00.000Z') });
event.setValue({ fieldId: 'enddate', value: new Date('2023-02-28T09:00:00.000Z') });
// event.setValue({ fieldId: 'starttime', value: startTime });
// event.setValue({ fieldId: 'endtime', value: endTime });
event.setValue({ fieldId: 'eventstatus', value: hardcodedMeeting.Status });
event.setValue({ fieldId: 'timedevent', value: true });
if (hardcodedMeeting.CustomerId) {
event.setValue({ fieldId: 'company', value: hardcodedMeeting.CustomerId });
}
if (hardcodedMeeting.Organizer) {
event.setValue({ fieldId: 'organizer', value: hardcodedMeeting.Organizer });
}
var eventId = event.save();
log.audit('Meeting Created', 'ID: ' + eventId);
context.response.write('<h2>Meeting Created Successfully</h2><p>ID: ' + eventId + '</p>');
} catch (e) {
log.error('Error Creating Meeting', e);
context.response.write('<h2>Error Creating Meeting</h2><p>' + e.message + '</p>');
}
}
}
return {
onRequest: onRequest
};
});
Celigo AI
05/30/2025, 5:31 AMAI generated answer (using internal Slack threads):Based on the conversations provided, it seems like you are trying to set the start and end times of a calendar event in NetSuite using SuiteScript. However, you are facing issues with the times not being set correctly. One of the issues could be related to the timezone. The server might be in a different timezone than the one you are in, which could cause the time to be off. You can use the
format
module to format the date and time according to a specific timezone. Here is an example:
javascript
function formatDateTimeCentral(dateObj) {
return format.format({
value: dateObj,
type: format.Type.DATETIME, // <-- DATETIME not DATE
timezone: format.Timezone.AMERICA_CHICAGO // Central Time
});
}
You can then use this function to set the start and end times:
javascript
rec.setValue('starttime', new Date(formatDateTimeCentral(new Date(START_TIME))))
rec.setValue('endtime', new Date(formatDateTimeCentral(new Date(END_TIME))))
Another issue could be related to the way you are setting the start and end times. In your code, you are setting the startdate
and enddate
fields, but you are not setting the starttime
and endtime
fields. You should uncomment these lines and set the starttime
and endtime
fields using the parsed start and end times:
javascript
event.setValue({ fieldId: 'starttime', value: startTime });
event.setValue({ fieldId: 'endtime', value: endTime });
Please note that the format.parse
function should be used to parse the date and time strings into Date objects. You should use the format.Type.DATETIME
type to parse the full datetime strings:
javascript
var startDateTime = format.parse({
value: startDateTimeString,
type: format.Type.DATETIME
});
var endDateTime = format.parse({
value: endDateTimeString,
type: format.Type.DATETIME
});
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
05/30/2025, 5:31 AMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847563446
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.844724119
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842219532
Celigo AI
05/30/2025, 5:31 AM