How to Stop MID Servers from AutoUpgrading On Weekends and HolidaysSummary<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } This article aims to assist customers whom may want to prevent their MID Servers from auto upgrading on weekends and holidays.This stems from use cases where a customer may be enrolled in ServiceNow's Patching Program or other implementation where an instance upgrade scheduled on a weekend or holiday slips by and the MID Servers fail their AutoUpgrade afterwards essentially leaving the MID Servers in an unplanned outage when minimal staff is available to upgrade the MID Servers manually.A procedure is outlined here on how to implement a daily Scheduled Script Execution Job that leverages a Schedule [cmn_schedule] to pin the MID Servers to their current version on a Weekend or Holiday and remove the pin when it's not a Weekend or a Holiday.Other days and dates can be added to the Schedule if you want. Please see ServiceNow Product Documentation Define a Schedule for more information and procedure. Facts<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Important: If you use mid.pinned.version on a family release upgrade such as Yokohama to Xanandu, your MID Servers will be Down after the upgrade as they can not be on a different family release than the instance.Thus the Scheduled Job should disabled and all mid.pinned.version configuration parameters removed before a family release upgrade.Disclosure: These are custom scripts not officially supported in a ServiceNow base system and are viewed such as customizations where any technical debt is owned by the customer. Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } ALL Instructions<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } I. Create a Schedule [cmn_schedule] 1. Go to the Schedule [cmn_schedule] table 2. Click New 3. Set the Name field to MID Server Upgrade Blackout Dates 4. Set the Type field to mid_server_upgrade_blackouts ** Important: If you don't set type field to mid_server_upgrade_blackouts then the script for the scheduled job won't be able to find the Schedule. 5. Click Save and wait for the form to reload 6. Go to the Child Schedules related list on the MID Server Upgrade Blackout Dates Schedule record 7. Click Edit 8. Add U.S. Holidays to the Child Schedules List on the right 9. Click Save and wait for the form to reload 10. Go to the Schedule Entries related list on the MID Server Upgrade Blackout Dates Schedule record 11. Click New 12. Set Name to Weekends for MID Server Upgrade Blackout 13. Set Type to Excluded 14. Check the All day box 15. Set Repeats to Every Weekend (Sat, Sun) 16. Click Submit ** Some instances have been reported to block insert of new Schedule Entry [cmn_schedule_span] records depending on what other applications/plugins may be installed. In the case the Alternate Procedure to create the Schedule Entry can be followed. 1. In the navigation filter of the application navigator type cmn_schedule_span.list and press Enter. 2. Select an existing weekend Schedule Entry and open it. 3. Set Name to Weekends for MID Server Upgrade Blackout 4. Set Type to Excluded 5. Check the All day box 6. Set Repeats to Every Weekend (Sat, Sun) 7. Change the referenced Schedule to the MID Server Upgrade Blackout Dates schedule 8. Click the Additional Actions ☰ collapsable menu at top left of the form and select Insert and Stay create the new record. II. Create the Scheduled Script Execution [sysauto_script] 1. In the navigation filter of the application navigator type sysauto_script.list and press Enter. 2. Click New 3. Give the Scheduled Script a name like MID Server Upgrade Blackout 4. Set the Run field to Daily at 00:00:00 5. Copy and Paste below into the Script field checkMidPinnedVersions(); function checkMidPinnedVersions(){ var blackOutDate = isBlackOutDate(); if(blackOutDate == 'true'){ gs.info("Pinning all MID Servers to their current version"); pinMIDServers(); }else if(blackOutDate == 'false'){ gs.info("Searching for Pinned MID Servers "); removePins(); } } // If blackOutDate is true // Pin all MID Servers to their current version function updateMIDConfigParam(agent,parm,value,status){ var gr = new GlideRecord('ecc_agent_config'); gr.addQuery('ecc_agent', agent); gr.addQuery('param_name', parm); gr.query(); if(gr.next()) { if(gr.getValue('value')!= value){ gr.value = value; if(status == 'Down'){ gr.setWorkflow(false); } gr.update(); gs.info("Updated config param for agent: " + agent + ", param: " + parm + ", value: " + value); } }else{ var newConfigParm = new GlideRecord('ecc_agent_config'); newConfigParm.initialize(); newConfigParm.ecc_agent = agent; newConfigParm.param_name = parm; newConfigParm.value = value; if(status == 'Down'){ newConfigParm.setWorkflow(false); } newConfigParm.insert(); gs.info("Created config param for agent: " + agent + ", param: " + parm + ", value: " + value); } } function pinMIDServers() { var gr = new GlideRecord('ecc_agent'); gr.query(); while (gr.next()) { var agent = gr.getValue('sys_id'); var version = gr.getValue('version'); var parm = "mid.pinned.version"; var status = gr.getValue('status'); updateMIDConfigParam(agent,parm,version,status); } } // If blackOutDate is false remove all pins function removePins(){ var gr = new GlideRecord('ecc_agent_config'); gr.addQuery('param_name', 'mid.pinned.version'); gr.query(); while(gr.next()){ var midServerName = gr.getDisplayValue('ecc_agent'); var midStatus = gr.ecc_agent.status.toString(); gs.info("Found MID Server " + midServerName + " pinned to " + gr.getValue('value')); if(midStatus == 'Down'){ gr.setWorkflow(false); } gr.deleteRecord(); gs.info("Removed mid.pinned.version from " + midServerName); } if(gr.getRowCount() < 1){ gs.info("No Pinned MID Servers found."); } } // Get MID Black Out Date Schedule's SysID function getScheduleID(){ var scheduleId = ""; var gr = new GlideRecord('cmn_schedule'); gr.addEncodedQuery('typeSTARTSWITHmid_server_upgrade_blackout'); gr.query(); if(gr.next()){ scheduleId = gr.getValue('sys_id'); } return scheduleId; } // Check if today is black out day function isBlackOutDate() { var scheduleSysId = getScheduleID(); // MID Server Upgrade Blackout Dates //var scheduleSysId = '08fcd0830a0a0b2600079f56b1adb9ae'; // 8-5 Weekdays if(scheduleSysId){ var currentDate = new GlideDateTime(); var schedule = new GlideSchedule(scheduleSysId); var inSchedule = schedule.isInSchedule(currentDate); if (inSchedule) { gs.info("Today (" + currentDate + ") is a MID Server Upgrade Blackout Date according to schedule: " + scheduleSysId); return 'true'; } else { gs.info("Today (" + currentDate + ") is not a MID Server Upgrade Blackout Date according to schedule: " + scheduleSysId); return 'false'; } }else{ gs.warn("\nMID Server Upgrade Blackout Date not found on the cmn_schedule table.\nPlease check that the schedule is on the cmn_schedule table and that it's Type field is set to mid_server_upgrade_blackouts"); } } Related Links<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } https://www.servicenow.com/docs/csh?topicname=t_DefineASchedule.html&version=latest https://www.servicenow.com/docs/csh?topicname=mid-server-version-selection.html&version=latest https://www.servicenow.com/docs/csh?topicname=c_UpgradeAndTestMIDServer.html&version=latest