Auto-populate CAB date on Tuesday/Thursday at 9:30am

IB98
Giga Sage

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);

 

1 ACCEPTED SOLUTION

Raghu Ram Y
Kilo Sage

I guess it was the same issue, you can close this thread.

View solution in original post

4 REPLIES 4

Tony Chatfield1
Kilo Patron

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?

 

 

 

 

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

Raghu Ram Y
Kilo Sage

I guess it was the same issue, you can close this thread.

please refer to this link for the solution!!!

https://community.servicenow.com/community?id=community_question&sys_id=0b2af2411b228910d018c8ca234bcbd4&anchor=answer_c029e3551bae0150d018c8ca234bcb5b