How To Create a Scheduled Job to Automate Pinning and Unpinning MID Server versionsSummary<!-- /*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: ; } } The supported process of using the mid.pinned.version parameter to delay the MID Server AutoUpgrade after an instance upgrade is to set the parameter manually for each MID Server that you want to pin before the instance upgrade and then manually unpin them after the upgrade when you want to upgrade the MID Servers.This article provides steps to implement a Scheduled Script Execution that can set the mid.pinned.version MID Server Configuration Parameter to the current version of that MID Server before an instance upgrade to override the automatic MID Server AutoUpgrade.This article also provides steps to implement a Scheduled Script Execution that can set the mid.pinned.version MID Server Configuration Parameter to the value of System Property mid.version after an instance upgrade.The goal of both Scheduled Scripts is to automate pinning the version of the MID Servers with the added ability to schedule when to set mid.pinned.version to the current mid.version property and essentially control the time you want the MID Servers to upgrade after the instance has upgraded. 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.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.That being said, please feel free to change to scripts to suit your own business needs as you see fit. 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 Scheduled Script Execution to Create or Update the mid.pinned.version MID Server Configuration Parameter with the current version of each MID Server. This script iterates over all MID Servers on the instance and sets mid.pinned.version with the value in that MID Server's 'version' field. 1. Go to the Scheduled Script Executions [sysauto_script] table. 2. Click New 3. Give the Scheduled Script a name like "Pin MID Servers to their current versions" 4. Set the Run field to On Demand 5. Copy and Paste below into the Script field pinMIDServers(); 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); } } 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()) { 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); } } II. Create a Scheduled Script Execution to Create or Update the mid.pinned.version MID Server Configuration Parameter with the version in System Property mid.version. This should be run post instance upgrade when you want to set mid.pinned.version to current version that the MID Server needs to upgrade to in order to not be on a different version than the instance. Below instructions are to set it to run On Demand, however you can also set it to Run Once at a scheduled time of after a scheduled instance upgrade. 1. Go to the Scheduled Script Executions [sysauto_script] table. 2. Click New 3. Give the Scheduled Script a name like "Pin MID Servers to current MID Build Stamp" 4. Set the Run field to On Demand 5. Copy and Paste below into the Script field function pinMIDServersToLatestVersion() { var gr = new GlideRecord('ecc_agent'); gr.query(); while (gr.next()) { var agent = gr.getValue('sys_id'); var version = gs.getProperty('mid.version'); var parm = "mid.pinned.version"; var status = gr.getValue('status'); updateMIDConfigParam(agent,parm,version,status); } } 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()) { 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); } } 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: ; } } ServiceNow Product Documentation MID Server upgrades Pinning a MID Server to a specific version