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

Automate change request with change tasks creation for monthly patching activities

Arjun Reddy Yer
Mega Sage

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

ArjunReddyYer_0-1765391652132.png

2. Monthly PMPC Patching

ArjunReddyYer_1-1765391782557.png

Assignment Groups:

 

  1. Supply Chain Engineering
  2. Corporate Engineering
  3. Digital Engineering

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Arjun Reddy Yer 

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

})();

AnkurBawiskar_0-1765422956405.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

27 REPLIES 27

Dr Atul G- LNG
Tera Patron

HI @Arjun Reddy Yer 

You can try using Flow Designer and apply the Change Model — that will work better and you can mark where you define each step. As per the Zurich release, you can set the schedule the way you showed.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

bad luck as not to use flow designer or workflow

The sad part is educating the client to use Flow — it really makes your life easier, mate

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Dr Atul G- LNG
Tera Patron

DrAtulGLNG_0-1765471366232.png

 

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

@Dr Atul G- LNG 

I believe with Flow it can't be scheduled on 2nd Friday of the month.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader