We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

To set the due date of RITM and Catalog task to every Friday

Ankitha4
Tera Contributor

Hi, can anyone please help me with the query, I need to set the due date of Requested Item and Catalog task to Friday .

3 REPLIES 3

Sandeep Rajput
Tera Patron

@Ankitha4 you can create an on Insert before business rule on Requested Item and Catalog task table and keep the script as follows.

 

(function executeRule(current, previous /*null when async*/) {
    // Get today's day (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
    var today = new GlideDateTime();
    var dayOfWeek = today.getDayOfWeek(); 
    
    // Calculate the days remaining to the upcoming Friday (Friday = 5)
    var daysToFriday = 5 - dayOfWeek;
    if (daysToFriday < 0) {
        daysToFriday += 7; // If already past Friday, move to the next week
    }
    
    // Add the days to the current date
    today.addDaysLocalTime(daysToFriday);
    
    // Set the due date to the calculated Friday
    current.due_date = today;
    
})(current, previous);

Hope this helps.

Thanks Sandeep for the reply . Can I use the same script in the client script of catalog item 

@Ankitha4 The business rule I shared is a server side code. If you need to use this in the client script then you need to create a Client callable script include put the above script inside a script include function and call it from a catalog client script using GlideAjax.

 

Please mark the response helpful and accepted solution if it manages to answer your question.