- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 05:30 AM
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 ???
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 05:45 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 05:45 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 07:06 AM
Thankyou buddy for confirmation , i am also thinking that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 06:01 AM
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
}