<?xml version="1.0" encoding="UTF-8"?><unload unload_date="2019-03-29 18:19:02">
<sys_remote_update_set action="INSERT_OR_UPDATE">
<application display_value="Global">global</application>
<application_name>Global</application_name>
<application_scope>global</application_scope>
<application_version/>
<collisions/>
<commit_date/>
<deleted/>
<description/>
<inserted/>
<name>SNG-Parse Catalog Variables from URI-v1.0</name>
<origin_sys_id/>
<parent display_value=""/>
<release_date/>
<remote_base_update_set display_value=""/>
<remote_parent_id/>
<remote_sys_id>9b623f643724370090b68cf6c3990ea8</remote_sys_id>
<state>loaded</state>
<summary/>
<sys_class_name>sys_remote_update_set</sys_class_name>
<sys_created_by>SNProTips</sys_created_by>
<sys_created_on>2019-03-29 18:19:01</sys_created_on>
<sys_id>a86333a43724370090b68cf6c3990ea6</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_updated_by>SNProTips</sys_updated_by>
<sys_updated_on>2019-03-29 18:19:01</sys_updated_on>
<update_set display_value=""/>
<update_source display_value=""/>
<updated/>
</sys_remote_update_set>
<sys_update_xml action="INSERT_OR_UPDATE">
<action>INSERT_OR_UPDATE</action>
<application display_value="Global">global</application>
<category>customer</category>
<comments/>
<name>item_option_new_set_74c273a43724370090b68cf6c3990ea4</name>
<payload><![CDATA[<?xml version="1.0" encoding="UTF-8"?><record_update table="item_option_new_set"><item_option_new_set action="INSERT_OR_UPDATE"><create_roles/><description>Parses variables from the "sysparm_variables" URI parameter, to populate variables on a catalog item.</description><display_title>false</display_title><internal_name>parse_uri_vars</internal_name><layout>normal</layout><name/><order>100</order><read_roles/><sys_class_name>item_option_new_set</sys_class_name><sys_created_by>SNProTips</sys_created_by><sys_created_on>2019-03-29 18:17:40</sys_created_on><sys_id>74c273a43724370090b68cf6c3990ea4</sys_id><sys_mod_count>0</sys_mod_count><sys_name>Parse Variables from URI Params</sys_name><sys_package display_value="Global" source="global">global</sys_package><sys_policy/><sys_scope display_value="Global">global</sys_scope><sys_update_name>item_option_new_set_74c273a43724370090b68cf6c3990ea4</sys_update_name><sys_updated_by>SNProTips</sys_updated_by><sys_updated_on>2019-03-29 18:17:40</sys_updated_on><title>Parse Variables from URI Params</title><type>one_to_one</type><write_roles/></item_option_new_set></record_update>]]></payload>
<payload_hash>1463482711</payload_hash>
<remote_update_set display_value="SNG-Parse Catalog Variables from URI-v1.0">a86333a43724370090b68cf6c3990ea6</remote_update_set>
<replace_on_upgrade>false</replace_on_upgrade>
<sys_created_by>SNProTips</sys_created_by>
<sys_created_on>2019-03-29 18:19:01</sys_created_on>
<sys_id>e46333a43724370090b68cf6c3990ea7</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_recorded_at>169caabf2a40000001</sys_recorded_at>
<sys_updated_by>SNProTips</sys_updated_by>
<sys_updated_on>2019-03-29 18:19:01</sys_updated_on>
<table/>
<target_name>Parse Variables from URI Params</target_name>
<type>Variable Set</type>
<update_domain>global</update_domain>
<update_guid>7013fb64d72437002dec6fcd81b3bce3</update_guid>
<update_guid_history>7013fb64d72437002dec6fcd81b3bce3:1463482711</update_guid_history>
<update_set display_value=""/>
<view/>
</sys_update_xml>
<sys_update_xml action="INSERT_OR_UPDATE">
<action>INSERT_OR_UPDATE</action>
<application display_value="Global">global</application>
<category>customer</category>
<comments/>
<name>catalog_script_client_b523f7a43724370090b68cf6c3990e37</name>
<payload>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;record_update sys_domain="global" table="catalog_script_client"&gt;&lt;catalog_script_client action="INSERT_OR_UPDATE"&gt;&lt;active&gt;true&lt;/active&gt;&lt;applies_catalog&gt;true&lt;/applies_catalog&gt;&lt;applies_extended&gt;false&lt;/applies_extended&gt;&lt;applies_req_item&gt;false&lt;/applies_req_item&gt;&lt;applies_sc_task&gt;false&lt;/applies_sc_task&gt;&lt;applies_target_record&gt;false&lt;/applies_target_record&gt;&lt;applies_to&gt;set&lt;/applies_to&gt;&lt;cat_item/&gt;&lt;cat_variable/&gt;&lt;condition/&gt;&lt;description/&gt;&lt;field/&gt;&lt;global&gt;true&lt;/global&gt;&lt;isolate_script&gt;true&lt;/isolate_script&gt;&lt;messages/&gt;&lt;name&gt;Parse sysparm_variables URI param&lt;/name&gt;&lt;order/&gt;&lt;script&gt;&lt;![CDATA[/*
	This script is part of a variable set which can be included on any catalog item, in order to enable this functionality.
	When this script (or the "Set variables from URL" variable set) are included on a catalog item, then any variable(s) on that catalog item can be set on-load, by manipiulating the URL to the catalog item. You'll simply need to add a URI parameter called "sysparm_variables", and set the value of that parameter to a JSON-formatted string containing key/value pairs, where the key is a valid variable name, and the value is a valid value for that variable (for example, a sys_id in the case of a reference field).
	
	The contents of the sysparm_variables object should be minimally encoded first as a JSON object, and secondly as a URL.
	JSON encoding means you'll need to escape certain characters (such as backslashes) like so:
		{"os_root":"C:\\windows"}
	Notice how I've used two backaslashes after "C:" in the value above? This is the escape sequence for a single backslash.
	
	URL encoding means that you'll need to escape certain other characters (such as spaces and ampersands) with URL-encoding sequences like so:
		{"name":"Tim%20Woodruff"}
	Notice how I've used "%20" in place of the space between my first and last name. This is because URLs do not accept spaces (though most browsers handle that for you automatically, which we'll discuss below)
	
	Most modern programming languages (including JavaScript) also have methods for encoding and decoding URLs, so you can take any JSON-encoded string, run it through one of those functions, and use the result in your URL. *IF* you're URL-encoding something with backslashes in it, you'll have to *double-escape* them - they'll be escaped for the JSON encoding, and again for the URL encoding. For example:
		encodeURIComponent('{"program_files_dir":"C:\\\\Program Files (x86)"}');
	The above line of code will print the following string:
		%7B%22program_files_dir%22%3A%22C%3A%5C%5CProgram%20Files%20(x86)%22%7D
	If you look closely, you'll see the URL-encoded backslash character ("%5C") twice, not four times. This is because the "encodeURIComponent" function interpreted only two escaped backslashes, rather than four unescaped backslashes. That results in the correctly encoded version of the string "C:\Program Files (x86)", because when un-encoded, the two remaining backslashes will be interpreted as, again, a single *escaped* backslash. If you're not pre-URL-encoding the sysparm_variables object's value, then you only need to escape backslashes once, as mentioned above.
	
	Most browsers will automatically encode URLs with invalid characters, but it's best to be safe and at least encode certain characters. You can manually URL-encode certain characters like spaces (%20) without having to worry about all of the extra bother of double-escaping stuff like backslashes.
	
	Example usage: Simply append the following to the URL of the catalog item in either your service portal, or the classic UI:
		&amp;sysparm_variables={"catalog_variable_name":"variable%20value","var_name_2":"second%20variable%20value"}
	
	This functionality should function identically for catalog items on both the classic, and the portal UI.
*/
function onLoad() {
	
	var prop, propVal;
	//get parameter from URL
	var objVariables = getParameterValue('sysparm_variables');
	console.debug('sysparm_variables URI parameter value: ' + objVariables);
	if (!objVariables || objVariables == '' || objVariables.indexOf('{') != 0) {
		//If variables is empty or not properly formatted, stop here.
		console.debug('aborting due to a missing or problematic sysparm_variables URI parameter');
		return;
	}
	objVariables = JSON.parse(objVariables);
	console.debug('sysparm_variables URI parameter value: ' + JSON.stringify(objVariables));
	
	for (prop in objVariables) {
		if (!objVariables.hasOwnProperty(prop)) {
			break;
		}
		propVal = objVariables[prop];
		console.debug('Processing property ' + prop + ' with value ' + propVal);
		
		if (g_form.hasField(prop)) {
			console.debug('Setting variable ' + prop + ' to value ' + propVal);
			g_form.setValue(prop, propVal);
		} else {
			console.warn('Variable ' + prop +
				', specified in the sysparm_variables URI parameter, does not exist on this catalog item form.');
		}
	}
}

function getParameterValue(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&amp;]" + name + "=([^&amp;#]*)";
	var regex = new RegExp(regexS);
	//Check if portal (gel=undefined) or classic UI, and get the HREF data appropriately in either case.
	var hrefPath = (typeof gel == 'undefined') ? this.location.href : top.location.href;
	var results = regex.exec(hrefPath);
	
	console.debug('HREF: ' + hrefPath);
	
	if (results == null) {
		return "";
	} else {
		return unescape(results[1]);
	}
}]]&gt;&lt;/script&gt;&lt;sys_class_name&gt;catalog_script_client&lt;/sys_class_name&gt;&lt;sys_created_by&gt;SNProTips&lt;/sys_created_by&gt;&lt;sys_created_on&gt;2019-03-29 18:18:29&lt;/sys_created_on&gt;&lt;sys_domain&gt;global&lt;/sys_domain&gt;&lt;sys_domain_path&gt;/&lt;/sys_domain_path&gt;&lt;sys_id&gt;b523f7a43724370090b68cf6c3990e37&lt;/sys_id&gt;&lt;sys_mod_count&gt;0&lt;/sys_mod_count&gt;&lt;sys_name&gt;Parse sysparm_variables URI param&lt;/sys_name&gt;&lt;sys_overrides/&gt;&lt;sys_package display_value="Global" source="global"&gt;global&lt;/sys_package&gt;&lt;sys_policy/&gt;&lt;sys_scope display_value="Global"&gt;global&lt;/sys_scope&gt;&lt;sys_update_name&gt;catalog_script_client_b523f7a43724370090b68cf6c3990e37&lt;/sys_update_name&gt;&lt;sys_updated_by&gt;SNProTips&lt;/sys_updated_by&gt;&lt;sys_updated_on&gt;2019-03-29 18:18:29&lt;/sys_updated_on&gt;&lt;table/&gt;&lt;type&gt;onLoad&lt;/type&gt;&lt;ui_type&gt;10&lt;/ui_type&gt;&lt;variable_set display_value="Parse Variables from URI Params"&gt;74c273a43724370090b68cf6c3990ea4&lt;/variable_set&gt;&lt;view/&gt;&lt;/catalog_script_client&gt;&lt;/record_update&gt;</payload>
<payload_hash>-1700562784</payload_hash>
<remote_update_set display_value="SNG-Parse Catalog Variables from URI-v1.0">a86333a43724370090b68cf6c3990ea6</remote_update_set>
<replace_on_upgrade>false</replace_on_upgrade>
<sys_created_by>SNProTips</sys_created_by>
<sys_created_on>2019-03-29 18:19:01</sys_created_on>
<sys_id>ec6333a43724370090b68cf6c3990ea6</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_recorded_at>169caacb3810000001</sys_recorded_at>
<sys_updated_by>SNProTips</sys_updated_by>
<sys_updated_on>2019-03-29 18:19:01</sys_updated_on>
<table/>
<target_name>Parse sysparm_variables URI param</target_name>
<type>Catalog Client Scripts</type>
<update_domain>global</update_domain>
<update_guid>f443b7a41624370059f2d25d16862c39</update_guid>
<update_guid_history>f443b7a41624370059f2d25d16862c39:-1700562784</update_guid_history>
<update_set display_value=""/>
<view/>
</sys_update_xml>
</unload>
