If you’ve worked with MID Server Script Includes, you’ll know how frustrating it is that the script does not auto populate with a default script when you set the name of the MID Server Script Include. Below you’ll find a simple client script, based on the ServiceNow provided script for platform Script Includes. You should create this in the Global scope.
Field | Value |
Name | Make default script |
Table | MID Server Script Include [ecc_agent_script_include] |
UI Type | Desktop |
Type | onChange |
Field name | Name |
Active | True |
Global | True |
Isolate script | False |
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '')
return;
// workaround for the fact that oldValue always comes in as the ORIGINAL value...
if (window._lastNameChangedTo)
oldValue = window._lastNameChangedTo;
window._lastNameChangedTo = newValue;
var script = '' + g_form.getValue('script');
// if there's already a script here, just fix the names...
if (script) {
//Make sure there's an old value to replace or else it will replace every character
//with the new value
if (oldValue !== '')
script = script.replace(new RegExp(oldValue, 'g'), newValue);
} else {
script = 'var ' + newValue + ' = Class.create();\n';
script += newValue + '.prototype = {\n';
script += ' initialize: function() {\n';
script += ' },\n\n';
script += ' type: \'' + newValue + '\'\n';
script += '};';
}
g_form.setValue('script', script);
}
Alternatively, you can use the link below to download an update set that contains this Client Script for you.