<?xml version="1.0" encoding="UTF-8"?><unload unload_date="2019-11-25 23:01:58">
<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-Get RITM Vars via REST API-v2.1</name>
<origin_sys_id/>
<parent display_value=""/>
<release_date/>
<remote_base_update_set display_value=""/>
<remote_parent_id/>
<remote_sys_id>5214b11a379d045090b68cf6c3990e55</remote_sys_id>
<state>loaded</state>
<summary/>
<sys_class_name>sys_remote_update_set</sys_class_name>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2019-11-25 23:01:58</sys_created_on>
<sys_id>034bb95237dd045090b68cf6c3990ea7</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2019-11-25 23:01:58</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>sys_ws_definition_09817ffa37ec730090b68cf6c3990e10</name>
<payload><![CDATA[<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_ws_definition"><sys_ws_definition action="INSERT_OR_UPDATE"><active>true</active><base_uri>/api/13231/ritm_vars_api</base_uri><consumes>application/json,application/xml,text/xml</consumes><consumes_customized>false</consumes_customized><default_version>No active default version</default_version><doc_link/><enforce_acl>cf9d01d3e73003009d6247e603f6a990</enforce_acl><is_versioned>false</is_versioned><name>RITM Vars API</name><namespace>13231</namespace><produces>application/json,application/xml,text/xml</produces><produces_customized>false</produces_customized><service_id>ritm_vars_api</service_id><short_description/><sys_class_name>sys_ws_definition</sys_class_name><sys_created_by>admin</sys_created_by><sys_created_on>2019-04-05 17:57:41</sys_created_on><sys_id>09817ffa37ec730090b68cf6c3990e10</sys_id><sys_mod_count>2</sys_mod_count><sys_name>RITM Vars API</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>sys_ws_definition_09817ffa37ec730090b68cf6c3990e10</sys_update_name><sys_updated_by>admin</sys_updated_by><sys_updated_on>2019-04-05 17:59:41</sys_updated_on></sys_ws_definition></record_update>]]></payload>
<payload_hash>-1197587906</payload_hash>
<remote_update_set display_value="SNG-Get RITM Vars via REST API-v2.1">034bb95237dd045090b68cf6c3990ea7</remote_update_set>
<replace_on_upgrade>false</replace_on_upgrade>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2019-11-25 23:01:58</sys_created_on>
<sys_id>0f4bb95237dd045090b68cf6c3990ea7</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_recorded_at>169eea801b40000001</sys_recorded_at>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2019-11-25 23:01:58</sys_updated_on>
<table/>
<target_name>RITM Vars API</target_name>
<type>Scripted REST API</type>
<update_domain>global</update_domain>
<update_guid>b112773efdec73004e226c87a2b7caee</update_guid>
<update_guid_history>b112773efdec73004e226c87a2b7caee:-1197587906,fc123776cfec7300d0607220b65aa392:2038284928,9ca177f6c8ec730086954faafdef5415:-1197587906</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>sys_script_include_28c2337e37ec730090b68cf6c3990e5a</name>
<payload>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;record_update table="sys_script_include"&gt;&lt;sys_script_include action="INSERT_OR_UPDATE"&gt;&lt;access&gt;package_private&lt;/access&gt;&lt;active&gt;true&lt;/active&gt;&lt;api_name&gt;global.trimAndSplit&lt;/api_name&gt;&lt;caller_access/&gt;&lt;client_callable&gt;false&lt;/client_callable&gt;&lt;description/&gt;&lt;name&gt;trimAndSplit&lt;/name&gt;&lt;script&gt;&lt;![CDATA[/**
 * Converts a string to an array, much like .split(), except that it trims each element of leading and trailing whitespace.
 * @param inputString {string} The string that should be split and trimmed
 * @param [token=,] {string} The character to split on (usually ','). Default value is a comma character.
 * @returns {Array} An array of elements that have each been trimmed of whitespace.
 */
function trimAndSplit(inputString, token) {
	var i, inputArr;
	var resultArray = [];
	
	//Give token a default value if not specified
	token = (!token) ? ',' : token;
	
	if (!inputString || typeof inputString !== 'string') {
		gs.logError(
			'trimAndSplit function received an invalid argument in the first argument. The argument received was: ' +
			inputString +
			'. The only acceptable first argument for trimAndSplit, is a string.');
		return [];
	}
	if (inputString.indexOf(token) &lt; 0) {
		//Return the original string in an array, because no instances of the token were found.
		return [inputString];
	}
	
	//convert the input string to an array, splitting on the provided token (usually ',')
	inputArr = inputString.split(token);
	for (i = 0; i &lt; inputArr.length; i++) {
		//Trim each element in the split string array, then push it to the return array.
		resultArray.push(inputArr[i].trim());
	}
	
	//return the trimmed and split array.
	return resultArray;
}]]&gt;&lt;/script&gt;&lt;sys_class_name&gt;sys_script_include&lt;/sys_class_name&gt;&lt;sys_created_by&gt;admin&lt;/sys_created_by&gt;&lt;sys_created_on&gt;2019-04-05 18:02:49&lt;/sys_created_on&gt;&lt;sys_id&gt;28c2337e37ec730090b68cf6c3990e5a&lt;/sys_id&gt;&lt;sys_mod_count&gt;1&lt;/sys_mod_count&gt;&lt;sys_name&gt;trimAndSplit&lt;/sys_name&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;sys_script_include_28c2337e37ec730090b68cf6c3990e5a&lt;/sys_update_name&gt;&lt;sys_updated_by&gt;admin&lt;/sys_updated_by&gt;&lt;sys_updated_on&gt;2019-11-25 22:50:39&lt;/sys_updated_on&gt;&lt;/sys_script_include&gt;&lt;/record_update&gt;</payload>
<payload_hash>-816399812</payload_hash>
<remote_update_set display_value="SNG-Get RITM Vars via REST API-v2.1">034bb95237dd045090b68cf6c3990ea7</remote_update_set>
<replace_on_upgrade>false</replace_on_upgrade>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2019-11-25 23:01:58</sys_created_on>
<sys_id>474bb95237dd045090b68cf6c3990ea7</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_recorded_at>16ea4c27ab70000001</sys_recorded_at>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2019-11-25 23:01:58</sys_updated_on>
<table/>
<target_name>trimAndSplit</target_name>
<type>Script Include</type>
<update_domain>global</update_domain>
<update_guid>51b8399e6e9d0450678e522359155410</update_guid>
<update_guid_history>51b8399e6e9d0450678e522359155410:-816399812,c687bd1ed69d04502ad059a93671bddc:1184288824,f277359a839d0450bdd857654da3422b:-462819513,8007311e989d045091d73f5e646bf088:-1384179843,4ac6bd5ae19d04502e698e2c6ff0a48a:938967086,67c2b73e80ec73008898e03f716dd703:1184288824</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>sys_ws_operation_9022f73e37ec730090b68cf6c3990e8e</name>
<payload>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;record_update table="sys_ws_operation"&gt;&lt;sys_ws_operation action="INSERT_OR_UPDATE"&gt;&lt;active&gt;true&lt;/active&gt;&lt;consumes&gt;application/json,application/xml,text/xml&lt;/consumes&gt;&lt;consumes_customized&gt;false&lt;/consumes_customized&gt;&lt;default_operation_uri/&gt;&lt;enforce_acl&gt;cf9d01d3e73003009d6247e603f6a990&lt;/enforce_acl&gt;&lt;http_method&gt;GET&lt;/http_method&gt;&lt;name&gt;get_vars&lt;/name&gt;&lt;operation_script&gt;&lt;![CDATA[(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
	var variableName, i, ritmVariables, ritmNumber, grRitm, variablesObject, ritmNumbers;
	var responseObj = {}; //The object that should ultimately be returned.
	
	//Set ritmNumber from header value, convert to an array, and trim each element.
	ritmNumbers = trimAndSplit(request.getHeader('ritm'), ','); //Calling custom script include.
	//ritmNumbers = request.getHeader('ritm').split(','); //&lt;--Commented out, but you can enable it if you don't have the trimAndSplit script include.
	
	if (!ritmNumbers) {
		//If ritm header was not set or was malformed, return an error.
		response.setStatus(417);
		return 'Unable to process request. Request header \'ritm\' not defined. ' +
			'Please define a request header called \'ritm\' with the value set to the ticket number for the RITM you\'d like to retrieve the variables for. Value provided for RITM: ' +
			ritmNumbers;
	}
	
	grRitm = new GlideRecord('sc_req_item');
	//For each RITM in the ritmNumbers array...
	for (i = 0; i &lt; ritmNumbers.length; i++) {
		//Get the RITM number
		ritmNumber = ritmNumbers[i];
		
		//Get the GlideRecord for the RITM, or throw an error if we can't.
		if (!grRitm.get('number', ritmNumber)) { //If we can't find the RITM...
			response.setStatus(417); //set the status to indicate a bad argument
			response.setHeader(ritmNumber,
				'Unable to locate requested ritm: ' + ritmNumber); //add a header to indicate which RITM was bad.
			gs.logError(
				'Scripted REST API ritm_vars_api unable to process request. RITM not found: ' +
				ritmNumber); //Log an error so the admin knows what happens if the requestor asks.
			continue; //Continue the loop with the next RITM in case there's anything valid we *can* return.
		}
		
		//Get the object containing the catalog variables.
		ritmVariables = grRitm.variables;
		//Declare a fresh object each loop.
		//This will be made to contain all of the variables and variable values for the RITM we're iterating over,
		//Then it will be pushed into the responseObj object, and reset for the next RITM on the next iteration.
		variablesObject = {};
		//Set the 'number' property on the variables object to the current ritm number. This will also be the
		variablesObject["number"] = ritmNumber;
		//Iterate over ritmVariables, looping through each one as v.
		//This is necessary because the "gr.variables" is not a standard JS object, and cannot be mapped.
		for (variableName in ritmVariables) {
			//NOTE: If you want to return all variables on the catalog item associated with the RITM, remove the second condition in the IF block below.
			//With the second condition, this will only show variables that have been populated.
			if (ritmVariables.hasOwnProperty(variableName) &amp;&amp; ritmVariables[variableName]) { //Make sure the property exists and isn't null or unknown.
				variableName = variableName.toString(); //Make sure we're all proper strings here.
				//pushing the variable into variablesObject, which will be copied into responseObject along with a version of variablesObject for each of the RITMs.
				variablesObject[variableName] = ritmVariables[variableName].toString();
			}
		}
		//Call addObjToObj function to add variablesObject to responseObj with the key set to the current RITM number, so it can be accessed as 'responseObj["RITM0123456"]'.
		//NOTE: If we didn't use addObjToObj, we'd run into this problem where objects are linked rather than copied, when added to other objects in javascript.
		responseObj = addObjToObj(responseObj, variablesObject, ritmNumber);
	}
	
	return responseObj; //Returning the variables and their values. Returning an object here will set the response "body" to the JSON equivalent of this object.
	
	//Helper function below
	function addObjToObj(parent, child, name) {
		parent[name] = child;
		return parent; //Note: Does not break pass-by-reference, because we're declaring a new object on each loop on line 39 above. 
	}
})(request, response);

]]&gt;&lt;/operation_script&gt;&lt;operation_uri&gt;/api/13231/ritm_vars_api&lt;/operation_uri&gt;&lt;produces&gt;application/json,application/xml,text/xml&lt;/produces&gt;&lt;produces_customized&gt;false&lt;/produces_customized&gt;&lt;relative_path&gt;/&lt;/relative_path&gt;&lt;request_example/&gt;&lt;requires_acl_authorization&gt;true&lt;/requires_acl_authorization&gt;&lt;requires_authentication&gt;true&lt;/requires_authentication&gt;&lt;requires_snc_internal_role&gt;true&lt;/requires_snc_internal_role&gt;&lt;short_description&gt;Returns a JSON object with all populated variables' names and values.&lt;/short_description&gt;&lt;sys_class_name&gt;sys_ws_operation&lt;/sys_class_name&gt;&lt;sys_created_by&gt;admin&lt;/sys_created_by&gt;&lt;sys_created_on&gt;2019-04-05 18:00:29&lt;/sys_created_on&gt;&lt;sys_id&gt;9022f73e37ec730090b68cf6c3990e8e&lt;/sys_id&gt;&lt;sys_mod_count&gt;3&lt;/sys_mod_count&gt;&lt;sys_name&gt;get_vars&lt;/sys_name&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;sys_ws_operation_9022f73e37ec730090b68cf6c3990e8e&lt;/sys_update_name&gt;&lt;sys_updated_by&gt;admin&lt;/sys_updated_by&gt;&lt;sys_updated_on&gt;2019-11-25 23:00:30&lt;/sys_updated_on&gt;&lt;web_service_definition display_value="RITM Vars API"&gt;09817ffa37ec730090b68cf6c3990e10&lt;/web_service_definition&gt;&lt;web_service_version/&gt;&lt;/sys_ws_operation&gt;&lt;/record_update&gt;</payload>
<payload_hash>476619440</payload_hash>
<remote_update_set display_value="SNG-Get RITM Vars via REST API-v2.1">034bb95237dd045090b68cf6c3990ea7</remote_update_set>
<replace_on_upgrade>false</replace_on_upgrade>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2019-11-25 23:01:58</sys_created_on>
<sys_id>474bb95237dd045090b68cf6c3990ea8</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_recorded_at>16ea4cb81a30000001</sys_recorded_at>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2019-11-25 23:01:58</sys_updated_on>
<table/>
<target_name>get_vars</target_name>
<type>Scripted REST Resource</type>
<update_domain>global</update_domain>
<update_guid>31fabdda9d9d0450aa70f915bccbcb5b</update_guid>
<update_guid_history>31fabdda9d9d0450aa70f915bccbcb5b:476619440,8356f3be3aec7300a4d32a0a6c3f68cc:1042604583,58627b3e00ec73007b9fb1f6b02308d4:-1569576793,ad427b3eebec7300ea8c51e8fd20f4c5:1725162780</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>sys_ws_header_map_d3e3f3be37ec730090b68cf6c3990ef3</name>
<payload><![CDATA[<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_ws_header_map"><sys_ws_header_map action="INSERT_OR_UPDATE"><sys_class_name>sys_ws_header_map</sys_class_name><sys_created_by>admin</sys_created_by><sys_created_on>2019-04-05 18:07:48</sys_created_on><sys_id>d3e3f3be37ec730090b68cf6c3990ef3</sys_id><sys_mod_count>0</sys_mod_count><sys_name>b483bf7e37ec730090b68cf6c3990e33</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>sys_ws_header_map_d3e3f3be37ec730090b68cf6c3990ef3</sys_update_name><sys_updated_by>admin</sys_updated_by><sys_updated_on>2019-04-05 18:07:48</sys_updated_on><web_service_header display_value="ritm">b483bf7e37ec730090b68cf6c3990e33</web_service_header><web_service_operation display_value="get_vars">9022f73e37ec730090b68cf6c3990e8e</web_service_operation></sys_ws_header_map></record_update>]]></payload>
<payload_hash>-1036112742</payload_hash>
<remote_update_set display_value="SNG-Get RITM Vars via REST API-v2.1">034bb95237dd045090b68cf6c3990ea7</remote_update_set>
<replace_on_upgrade>false</replace_on_upgrade>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2019-11-25 23:01:58</sys_created_on>
<sys_id>834bb95237dd045090b68cf6c3990ea8</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_recorded_at>169eeaf6ed70000001</sys_recorded_at>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2019-11-25 23:01:58</sys_updated_on>
<table/>
<target_name>b483bf7e37ec730090b68cf6c3990e33</target_name>
<type>Scripted REST Header Association</type>
<update_domain>global</update_domain>
<update_guid>2cf337bedaec7300c84e28c2f0401372</update_guid>
<update_guid_history>2cf337bedaec7300c84e28c2f0401372:-1036112742</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>sys_ws_header_b483bf7e37ec730090b68cf6c3990e33</name>
<payload><![CDATA[<?xml version="1.0" encoding="UTF-8"?><record_update table="sys_ws_header"><sys_ws_header action="INSERT_OR_UPDATE"><example_value>RITM0087923,RITM0087944,RITM0087801</example_value><name>ritm</name><required>true</required><short_description>The RITM number of the ticket(s) for which you'd like to retrieve the variables.</short_description><sys_class_name>sys_ws_header</sys_class_name><sys_created_by>admin</sys_created_by><sys_created_on>2019-04-05 18:06:42</sys_created_on><sys_id>b483bf7e37ec730090b68cf6c3990e33</sys_id><sys_mod_count>1</sys_mod_count><sys_name>ritm</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>sys_ws_header_b483bf7e37ec730090b68cf6c3990e33</sys_update_name><sys_updated_by>admin</sys_updated_by><sys_updated_on>2019-04-05 18:14:00</sys_updated_on><web_service_definition display_value="RITM Vars API">09817ffa37ec730090b68cf6c3990e10</web_service_definition></sys_ws_header></record_update>]]></payload>
<payload_hash>3026896</payload_hash>
<remote_update_set display_value="SNG-Get RITM Vars via REST API-v2.1">034bb95237dd045090b68cf6c3990ea7</remote_update_set>
<replace_on_upgrade>false</replace_on_upgrade>
<sys_created_by>admin</sys_created_by>
<sys_created_on>2019-11-25 23:01:58</sys_created_on>
<sys_id>cf4bb95237dd045090b68cf6c3990ea7</sys_id>
<sys_mod_count>0</sys_mod_count>
<sys_recorded_at>169eeb51da20000001</sys_recorded_at>
<sys_updated_by>admin</sys_updated_by>
<sys_updated_on>2019-11-25 23:01:58</sys_updated_on>
<table/>
<target_name>ritm</target_name>
<type>Scripted REST Header</type>
<update_domain>global</update_domain>
<update_guid>a35573be3fec7300394c03f9a8fedf23</update_guid>
<update_guid_history>a35573be3fec7300394c03f9a8fedf23:3026896,94b333be67ec7300c8159e8bcdb6ed83:-1678163559</update_guid_history>
<update_set display_value=""/>
<view/>
</sys_update_xml>
</unload>
