- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 08:06 AM
Hello,
I am trying to auto populate the CAB date with the preset CAB meetings if the risk is High and Cab required is true. My meetings are on Tuesday/Thursday at 9:30 am. I have a code that works but it only pulls in one day and it does not account for the time. Can someone please help me add the additional day and the filter conditions, please?
Thank you 🙂
BR
Before update
no conditions
(function executeRule(current, previous /*null when async*/ ) {
setCabDate();
function setCabDate() {
var start = current.start_date;
var startDate = new Date(start.replace(/-/g, "/"));
var nextThursday = getNextThursday(startDate);
var dateString = nextThursday.getFullYear() + "-" + ("0" + (nextThursday.getMonth() + 1)).slice(-2) + "-" + ("0" + (nextThursday.getDate())).slice(-2) + " 00:00:00";
var cabDate = new GlideDateTime(dateString);
current.cab_date = cabDate.getDate();
}
function getNextThursday(date) {
var daysUntilThursday = 4 - date.getDay();
if (daysUntilThursday < 0) {
daysUntilThursday += 7;
}
date.setTime(date.getTime() + daysUntilThursday * 86400000);
return date;
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 09:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 01:24 AM
Hi, unfortunately your issues\requirements are not clear in your post
You also state that your code does not account for the time, and 'only pulls in 1 date'
But the code appears to be date specific and getNextThursday() only references\returns the 1 day of the week.
Perhaps you could provide clear details of your business requirement.
I think you are trying to set a cab date based on the next valid cab meeting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 07:50 AM
Thank you so much on your reply! My requirement is to set the CAB date to: Tuesday/Thursday at 9:30am. I managed to get it to populate Thursday but I am not sure on how to add Tuesday to my code. Also, if it is noon on Tuesday, I want the code to pick up the next meeting date (ex. Thursday) because the meeting for Tuesday ended and the code needs check against that.
Does this make more sense now? 🙂
Thank you for your help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 09:32 AM
I guess it was the same issue, you can close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 09:40 AM
please refer to this link for the solution!!!
https://community.servicenow.com/community?id=community_question&sys_id=0b2af2411b228910d018c8ca234bcbd4&anchor=answer_c029e3551bae0150d018c8ca234bcb5b