Automate change request with change tasks creation for monthly patching activities
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
required help @Vasantharajan N @Ankur Bawiskar @Voona Rohila @WillieW @RaghavSh
As I need to automate the standard change request creation every 2nd Friday of the month for the change templates that I have with me along with that change tasks also need to create and those change tasks need to auto assign to assignment groups that I have with
Short Description: [assignment_group] Microsoft Patching
Description: New Microsoft patches installed
Change Template:
1. Monthly Microsoft Patching
2. Monthly PMPC Patching
Assignment Groups:
- Supply Chain Engineering
- Corporate Engineering
- Digital Engineering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you can create scheduled job which runs daily and it will check if today is 2nd Friday of mont
this you can check in condition of scheduled job
once condition becomes true you can write sample script below
answer = false;
var gdt = new GlideDateTime();
// 1 is Monday and 5 is Friday
if ((gdt.getDayOfMonthLocalTime() >= 8 && gdt.getDayOfMonthLocalTime() <= 14) && (gdt.getDayOfWeekLocalTime() == 5)) {
answer = true;
}
Script below
(function() {
var templateName = 'your_standard_change_template'; // Replace with your template name
var assignmentGroup = 'Microsoft Patching'; // Replace with your assignment group
var change = new GlideRecord('change_request');
change.initialize();
change.type = 'standard'; // Ensure the change type is standard
change.assignment_group.setDisplayValue(assignmentGroup);
// Apply the template
if (change.applyTemplate(templateName) == 0) {
gs.info('Template applied successfully to change request');
} else {
gs.info('Failed to apply template');
}
// Insert the change request
var changeSysId = change.insert();
gs.info('Standard change request created: ' + changeSysId);
// add logic here to create change tasks
})();
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Can you please check whether the below mentioned is correct or not for the Scheduled Script.
And what's the code that I need to add for Change Task creation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
the above will run Monthly on 4th day of month but won't work for your requirement with 2nd Friday of month
I shared the approach on how to execute job on 2nd Friday of month
Also gave you script to create CHG using template, now how to create change task you can use GlideRecord to insert change_task for that CHG
I believe I have answered your question and now you can enhance it further based on your developer skills and requirement.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
But when I select Run Type as Monthly then automatically Day is selected as "1"
As I changed it and selected as below can you please check once.
Can you provide script related to change task using GlideRecord for inserting change_task for the Change.