UI Macro Script - Need to update a field using Jelly Script

Hari7
Kilo Guru

I am trying to update priority of the case ticket based on the button selected on the case form. 

I want the Priority to be set to 2 only when the "jvar_cq" is selected and Priority to be set to 5 when "jvar_pq" is selected.

I am not sure how to get the if condition added based on the button click and dont have much knowledge on the Jelly Script.

Request you help me out on this. Thanks. 

UI Macro:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
	<j:set var="jvar_cq" value="cq_fac_routing${jvar_guid}:${ref}"/>
	<j:set var="jvar_pq" value="pq_faa_routing${jvar_guid}:${ref}"/>

	<g:reference_decoration id="${jvar_cq}" 
							field="${ref}" 
							onclick="setRouting('cq_fac_routing', '${ref}');" 							
							title="${gs.getMessage('Set as Counselor Question')}" 
							image="images/icons/tasks.gifx" 
							icon="icon-hr"/>
	
	<g:reference_decoration id="${jvar_pq}" 
							field="${ref}" 
							onclick="setRouting('pq_faa_routing', '${ref}');" 
							title="${gs.getMessage('Set as Phone Question')}" 
							image="images/icons/tasks.gifx" 
							icon="icon-phone"/>
	
	<script>
		// react to an onchange event
		// show link if populated, hide if not
		// move to js file for multiple inclusion
		function decorationShow(element, original, changed, loading) {
			var $refButtonCQ = $j(gel('${jvar_cq}'));
			var $refButtonPQ = $j(gel('${jvar_pq}'));
		
			var routingID = g_form.getValue('${ref}');
		
			var gaClientCaseRoutingUtils = new GlideAjax('CaseUtilsAjax');
			gaClientCaseRoutingUtils.addParam('sysparm_name', 'controlRoutingMacro');
			gaClientCaseRoutingUtils.addParam('sysparm_case_routing_lookup_id', routingID);
			gaClientCaseRoutingUtils.getXMLAnswer(function(response) {
				var macroObj = JSON.parse(response);
		
				if (macroObj.display) {
					$refButtonCQ.show();
					$refButtonPQ.show();
				} else {
					$refButtonCQ.hide();
					$refButtonPQ.hide();
				}
			});
		}

		// todo: SB nice extjs event model
		var n = '${ref}'.replace(/\./g, '_');
		var h = new GlideEventHandler('onChange_' + n, decorationShow, '${ref}');
		g_event_handlers.push(h);
		
		function setRouting(actionName, reference) {
			var gaClientCaseRoutingUtils = new GlideAjax('CaseUtilsAjax');
			gaClientCaseRoutingUtils.addParam('sysparm_name', 'getEMCCRouting');
			gaClientCaseRoutingUtils.addParam('sysparm_action_name', actionName);
			gaClientCaseRoutingUtils.addParam('sysparm_contact_id', g_form.getValue('contact'));
			gaClientCaseRoutingUtils.getXMLAnswer(function(response) {
				var routingObj = JSON.parse(response);
			
				for (var field in routingObj) {
					if (routingObj[field].display_value) {
						g_form.setValue(field, routingObj[field].value, routingObj[field].display_value);
						<!-- g_form.setValue('priority', '2');	 -->					
					} else {
						g_form.setValue(field, routingObj[field].value);
					}
				}
			});
		}
	</script>
</j:jelly>
6 REPLIES 6

Tried both the suggested changes but it didn't change the priority on the case form. 

Have to tried adding a logging statement inside of your getRouting() function to ensure that function is even getting called when you click one of the buttons? If it is, log the actionName and contactID values to ensure they are what you expect. Add logging statements just before the two g_form calls that set the priority field. Is the code making it to one of those logging statements? If it isn't, there's likely a problem with the code leading up to the calling of that function. You have to provide more context here than just stating that it's not working. Try to find out why it's not working.