MID Server Script Include – Default Script

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.

FieldValue
NameMake default script
TableMID Server Script Include [ecc_agent_script_include]
UI TypeDesktop
TypeonChange
Field nameName
ActiveTrue
GlobalTrue
Isolate scriptFalse

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.

Share this with your network

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top