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

Himanshu22
Tera Contributor

@kdurg : It doesn't work when passing from workspace script. Do you have any idea how to tackle that.

 

@Ankur Bawiskar 

Himanshu22
Tera Contributor

@kdurg  : It doesn't work when passing the scratchpad variable from workspace script in UI Action.

Do you have any idea how to tackle that.

 

@Ankur Bawiskar : Do you have any solution regarding this.

 

Right now I am trying to use this method with the code in my 
UI Action:

g_scratchpad.floor = 'abc123';

UI Page Client Script:

var data = g_scratchpad.floor;
console.log("Data: " + data);


In the console, this results in a log "Data: undefined".

Is there another step I am missing here?