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

@Arjun Reddy Yer 

I believe I have shared a working solution.

Today is 3rd Monday of Month so try to modify code for Monday and verify

Once it works then revert it with the script I shared for 2nd Thursday

💡 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

@Ankur Bawiskar @Dr Atul G- LNG @Vasantharajan N @Matthew_13 @SumanthDosapati with below script Change request and change task is getting created but the fields in the change request are not getting populated with the change template field values and it should execute on 2nd Thursday of every month so replaced with 4.

ArjunReddyYer_0-1765817117777.png

 

(function() {
    var templateName = 'sys ID of the Template'; // Replace with your template name
    
    var change = new GlideRecord('change_request');
    change.initialize();
    change.type = 'standard'; // Ensure the change type is standard

     // 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);

    // logic to create change tasks
	
    var rec = new GlideRecord('change_task');
    rec.initialize();
    rec.change_request = changeSysId;
    rec.short_description = 'Your Testing';
	rec.description = 'Confirm business application functions as it should with new Microsoft patches installed.';
    rec.assignment_group.setDisplayValue('Supply Chain Engineering');
    rec.insert();

})();

  Error when checked in Background script:

 

*** Script: Failed to apply template
#### Compiler Stats ####
Compiles: 1, time: 924ms
Total classes: 8, bytecode length: 0
Total loaders created: 8, unloaded: 8, existing: 0
Interpreted compiles: 18,800, time: 8,961ms
Cache name: "syscache_expression", max: 7,447, size: 7,678, seeks: 194,386,910, hits: 97,178,102, misses: 97,208,808, flushed: 0, row evictions: 0, single key evictions: 7,460, puts: 0, reclaims: 0, time from last reclaim to recreation total ms: 0, average time from last reclaim to recreation ms: 0
*** Script [TaskSLAFlow]: 2025-12-15 06:47:37.852 start: failed to start Flow "Default SLA flow" for Task SLA bfad3eca933db210fc57ff584dba1008:
com.snc.process_flow.exception.ProcessAutomationException: Failed to find complex object schema
*** Script [TaskSLAFlow]: 2025-12-15 06:47:37.883 start: failed to start Flow "Default SLA flow" for Task SLA 37ad3eca933db210fc57ff584dba100c:
com.snc.process_flow.exception.ProcessAutomationException: Failed to find complex object schema
Slow business rule 'Run SLAs' on change_request:<span class = "session-log-bold-text"> CHG0047407</span>, time was: 0:00:00.123
notification.provider: For Synchronous Providers: Loaded 0 recipients and 0 destinations and delivered to 0 destinations in 2ms
TriggerEngine:runEngine took 0.006ms to process for 'insert' operation on the record change_request[ffadba0e93f5b210fc57ff584dba101c]
*** Script: Standard change request created: ffadba0e93f5b210fc57ff584dba101c

The cleanup activity can be handled through a Flow or a Scheduled Job, but tasks are already straightforward and available out of the box. You can create a cleanup task using a standard change template and add the assignment there itself.

 

https://www.servicenow.com/docs/r/it-service-management/change-management/create-a-standard-change-t...

*************************************************************************************************************
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]

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

@Arjun Reddy Yer - Why don't you use the "Scheduled Standard Change Template" that has the Change task template included?

Screenshot 2026-01-29 125209.png

You can use the OOTB "advanced options" to run the schedule as per your need without coding, (Zurich)

 

https://www.servicenow.com/docs/r/platform-administration/time-configuration/advanced-options-for-sc...

 


Thanks & Regards,
Vasanth

thanks for the link but one thing is the Change Request is creating with Type: Normal not Standard