How to Pass Data from A UI Action To a UI Page

kdurg
Kilo Guru

Hey all, 
I am a bit stumped. I have looked up countless articles about how to pass a variable (the sys_id in my case) from a UI Action to a UI Page. When someone is on a Case, they can click a UI Action Button which would then send some form data (either from a glideAJAX call that will use the passed sys_id to look up and return case data, OR, a simpler solution- by passing g_form data for the required fields and pass those to the UI Page). 

I have used this as a guide

 

Here is the code:

UI Action Script

function showOpsGenieWidget() {
    var gm = new GlideModal('ops_genie_iframe');
	var sysID = g_form.getUniqueValue();
	var vendorName = g_form.getValue('u_vendor');
	jslog('sys id:: ' + vendorName + ' ' + sysID); // THIS DOES WORK, JUST CANT PASS THROUGH YET
    // gm.setPreference('sysID', sysID); // DOES NOT WORK SINCE THIS IS TO ADD TO A SPECIFIC FIELD ON A FORM
	
	
	gm.setWidth(1000);
    gm.setTitle('On-Call ' + sysID);
    gm.render();
}

 

 

UI Page HTML

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<j:set var="sysID" value="${RP.getParameterValue('sysID)}"/>
	<div>			
		<p>sysID is:: ${sysID} </p>
	</div>
<!-- 	<iframe class="opsgenie" src="/opsgenie"></iframe> -->
	 
	<footer class="modal-footer flex">
           <g:dialog_buttons_ok_cancel ok="return onOK();" cancel="return onCancel();" ok_type="button" cancel_type="button"/>
   </footer>
</j:jelly>

UI Page Client Script

function onOK() {
	gsftSubmit(null, g_form.getFormElement(), 'On Call');
}

function onCancel() {
   var o = GlideModal.prototype.get('SCOPE.On Call');
   o.destroy();
}

 

Any help would be appreciated. Thanks in advance.

1 ACCEPTED SOLUTION

kdurg
Kilo Guru

I was able to solve this using g_scratchpad. Here's how I used the scratchpad:

UI Action:

var sys_id=1234;
var vendor='This is the Vendor Name';
var caseNumber = 'abc1234567; 

var opsGenieOnCallInfo = {
	sys_id: sysID,
	vendor: vendorName,
	caseNumber: caseNumber
};
	
g_scratchpad.opsOnCallInfo = opsGenieOnCallInfo;


UI Page:

var passedData;

if (g_scratchpad.opsOnCallInfo){
	passedData = g_scratchpad.opsOnCallInfo;
}


From there I can use the data and place it into the HTML.

View solution in original post

7 REPLIES 7

Anil Lande
Kilo Patron

Hi,

Please check below links:

https://community.servicenow.com/community?id=community_question&sys_id=f038b4fa1b9df810ada243f6fe4b...

 

https://community.servicenow.com/community?id=community_question&sys_id=6612ec53db76abc0656a5583ca96...

 

https://community.servicenow.com/community?id=community_question&sys_id=9a008321db98dbc01dcaf3231f96...

 

 

 

Thnaks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

-O-
Kilo Patron
Kilo Patron

Maybe because you have a missing single quote in

RP.getParameterValue('sysID)

?

To make sure that you don't run into undocumented/poorly documented hidden quirks, I advise you to stick to the platform conventions - in this case use prefix 'sysparm_' (both in the UI Action and the UI Page):

gm.setPreference('sysparm_sysID', sysID);
<j:set var="jvar_sysID" value="${ RP.getParameterValue('sysparm_sysID'); }"/>

Not something that is documented, Jelly variables must start with the prefix jvar_ - as seen above.

-O-
Kilo Patron
Kilo Patron

Just to be clear, it seems prefixing URL parameters with sysparm_ is required.

kdurg
Kilo Guru

I was able to solve this using g_scratchpad. Here's how I used the scratchpad:

UI Action:

var sys_id=1234;
var vendor='This is the Vendor Name';
var caseNumber = 'abc1234567; 

var opsGenieOnCallInfo = {
	sys_id: sysID,
	vendor: vendorName,
	caseNumber: caseNumber
};
	
g_scratchpad.opsOnCallInfo = opsGenieOnCallInfo;


UI Page:

var passedData;

if (g_scratchpad.opsOnCallInfo){
	passedData = g_scratchpad.opsOnCallInfo;
}


From there I can use the data and place it into the HTML.