i will use this Script in Scheduled Jobs in Condition Field

1dusjhyahnt
Tera Contributor

Hi All, Please help me 

 

(function executeRule(current, previous /*null when async*/ ) {
    // Get current date
    var currentDate = new GlideDateTime();
    currentDate.setDayOfMonth(1); // Set day to the 1st of the month

 

    // Check if it's January, April, July, or October
    var month = currentDate.getMonth();
    if (month == 0 || month == 3 || month == 6 || month == 9) {
        // Check if it's the first Tuesday of the month
        if (currentDate.getDayOfWeek() == 1) { // 3 corresponds to Tuesday
            // Create incident here
            var newIncident = new GlideRecord('sc_task');
            newIncident.initialize(); // Initialize the record
            // Set other incident fields as needed
            newIncident.assignment_group="SN-APPS-WIPRO";
            newIncident.description = "Backup all computers, which are marked to be backed up manually";
            newIncident.insert(); // Insert the record
        }
    }
})(current, previous);

 

Hi , How i will use this Script in Scheduled Jobs in Condition Field ???

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

What are you trying to achieve? If this is a business rule you want to run as a scheduled job, just remove the first and last line (the function ones) and run it. Just curious why you are running a script creating a "newIncident" and you are creating a catalog task. And if you are creating a catalog task, shouldn't you create the RITM and REQ as well?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

3 REPLIES 3

Mark Manders
Mega Patron

What are you trying to achieve? If this is a business rule you want to run as a scheduled job, just remove the first and last line (the function ones) and run it. Just curious why you are running a script creating a "newIncident" and you are creating a catalog task. And if you are creating a catalog task, shouldn't you create the RITM and REQ as well?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Thankyou buddy for confirmation , i am also thinking  that 

Sandeep Raj Ram
Tera Contributor

Hi @1dusjhyahnt ,

 

If you are using this script in scheduled job, you will have to create answer variable in the Condition field and set it to true if conditions are matching. In the script section, you can use script to insert new record.

 

Condition Field:

var answer = false;

var currentDate = new GlideDateTime();
    currentDate.setDayOfMonth(1); // Set day to the 1st of the month

 

    // Check if it's January, April, July, or October
    var month = currentDate.getMonth();
    if (month == 0 || month == 3 || month == 6 || month == 9) {
        // Check if it's the first Tuesday of the month
        if (currentDate.getDayOfWeek() == 1) { // 3 corresponds to Tuesday

answer = true;

}

}

 

Run as Script Field:

// Create incident here
            var newIncident = new GlideRecord('sc_task');
            newIncident.initialize(); // Initialize the record
            // Set other incident fields as needed
            newIncident.assignment_group="SN-APPS-WIPRO";
            newIncident.description = "Backup all computers, which are marked to be backed up manually";
            newIncident.insert(); // Insert the record
        }