How to get the time in along with the date in glide duration in the business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 10:30 PM
Hi,
There is a business rule written on "sn_vul_vulnerable_item" table to calculate the business days. Below is the script for the same.
It is an onBefore business rule. Currently it is calculating the target date only based on the field "last_opened_dt_tm". My requirement is to calculate the time also along with the date. How can I do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 12:04 AM
then you need to have date/time field to be populated.
please share script here.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 12:37 AM
Hi Ankur,
Below is the existing script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 02:06 AM
you are already using schedule so it will add based on it and will give you output in time
update script as this
(function executeRule(current, previous /*null when async*/ ) {
//Fetching last Opened Date
var lastOpenedDate = new GlideDateTime(current.last_opened_dt_tm);
//Adding business days
var date = new GlideDateTime();
var days = parseInt(current.ttr_applied_rule.ttr_max);
var dur = new GlideDuration((60 * 60 * 8 * 1000 * days));
var schedule = new GlideSchedule('82fba44e877e655098264b59dabb35dd');
var newDateTime = schedule.add(date, dur);
//Updating new target date
current.ttr_target_date = remediationDate;
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 02:19 AM
Hi Ankur,
Thanks for the response!
I tried your script not working. I can see in logs "com.glide.script.RhinoEcmaError: "remediationDate" is not defined."