- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2024 09:06 PM
hi all
i do have a business rule that inserts a scheduled event the day an outage starts and at the start of the outage.
no issues to insert the event at the time the outage starts, but i cannot get the one at 00:00:00 of the day of the outage.
here is my code.
var outbegin = current.begin;
var samed = new GlideRecord(outbegin);
var theTime = '00:00:00';
var theDate = new GlideDate(outbegin) + ' 00:00:00';
gs.log('same day is ' + theDate);
if (samed== new GlideDate()){
gs.eventQueueScheduled("change.outage",current,'0',' ',theDate);
gs.eventQueueScheduled("change.outage",current,'now',' ',samed);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2024 09:40 PM
Hi @El Cuchi ,
Incorrect use of GlideRecord and GlideDate:
new GlideRecord(outbegin) and new GlideDate(outbegin) are not valid. GlideRecord is used to query a table, and GlideDate cannot be instantiated directly with a string. To work with date and time values, you should use GlideDateTime.String concatenation for dates:
Adding a time string to a GlideDate object ('00:00:00') won't work as intended. You need to construct a proper GlideDateTime object.
Logic error in if (samed == new GlideDate()):
This condition doesn't make sense in the context. samed is not properly defined or compared.
var outbegin = current.begin; // Assume 'begin' is a valid GlideDateTime field
var outBeginDateTime = new GlideDateTime(outbegin);
// Extract the date part from the start time and set time to '00:00:00'
var startOfDay = new GlideDateTime(outbegin);
startOfDay.setDisplayValue(startOfDay.getDate() + " 00:00:00");
// Log the start of the day for debugging
gs.log('Start of the day: ' + startOfDay);
// Queue the scheduled events
gs.eventQueueScheduled("change.outage", current, startOfDay, " ");
gs.eventQueueScheduled("change.outage", current, outBeginDateTime, " ");
GlideDateTime usage:
GlideDateTime is used to handle both date and time values.Setting time to 00:00:00:
The setDisplayValue method helps set the time to midnight (00:00:00) for the start of the day.Queueing the events:
Events are queued using the corrected startOfDay for midnight and outBeginDateTime for the actual start time of the outage.
The solution is helpful , Please mark it as Helpful.
Thanks & Regards
Arun Manoj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2024 09:38 PM
Hi @El Cuchi
Refer the below link.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2024 09:40 PM
Hi @El Cuchi ,
Incorrect use of GlideRecord and GlideDate:
new GlideRecord(outbegin) and new GlideDate(outbegin) are not valid. GlideRecord is used to query a table, and GlideDate cannot be instantiated directly with a string. To work with date and time values, you should use GlideDateTime.String concatenation for dates:
Adding a time string to a GlideDate object ('00:00:00') won't work as intended. You need to construct a proper GlideDateTime object.
Logic error in if (samed == new GlideDate()):
This condition doesn't make sense in the context. samed is not properly defined or compared.
var outbegin = current.begin; // Assume 'begin' is a valid GlideDateTime field
var outBeginDateTime = new GlideDateTime(outbegin);
// Extract the date part from the start time and set time to '00:00:00'
var startOfDay = new GlideDateTime(outbegin);
startOfDay.setDisplayValue(startOfDay.getDate() + " 00:00:00");
// Log the start of the day for debugging
gs.log('Start of the day: ' + startOfDay);
// Queue the scheduled events
gs.eventQueueScheduled("change.outage", current, startOfDay, " ");
gs.eventQueueScheduled("change.outage", current, outBeginDateTime, " ");
GlideDateTime usage:
GlideDateTime is used to handle both date and time values.Setting time to 00:00:00:
The setDisplayValue method helps set the time to midnight (00:00:00) for the start of the day.Queueing the events:
Events are queued using the corrected startOfDay for midnight and outBeginDateTime for the actual start time of the outage.
The solution is helpful , Please mark it as Helpful.
Thanks & Regards
Arun Manoj