RP.getParameterValue('sysparm_rec_id') is not working

Dazler
Mega Sage

Hi,

I am trying to pass variable in a URL from a UI Action to a UI Page.  The variable is passing to the URL, but when I try to pull it into the UI Page, it is blank.

What am I doing wrong?

We need this because the UI Page opens up in a new window and displays all the attachments of a catalog task ticket.  This will allow a print function.

But I need the sys_id of that catalog task to pass to the UI page, when the button is clicked on the catalog task.

This is my code in the HTML of the UI Page.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<!-- GLIDERECORD in JELLY -->
	<g2:evaluate var="jvar_attachments" object="true" jelly="true">
	
	<j:set var="jvar_sysID" value="${RP.getParameterValue('sysparm_rec_id')}"/>

		var sysID = jelly.jvar_sysID;
		var label = [];
        var sysAttachmentGR = new GlideRecord('sys_attachment');
        sysAttachmentGR.addQuery('table_sys_id', sysID);
		sysAttachmentGR.addQuery('table_name', 'sc_task');
        sysAttachmentGR.query();
		
		while(sysAttachmentGR.next()){
		
		label.push(sysAttachmentGR.sys_id.toString());
		
		}
				
		label;
			
	</g2:evaluate>

 

I have tried so many ways, but it keeps returning blank.

This is the code for the UI Action that passes the variable.

function openPrint() {

var scTask = g_form.getUniqueValue();
	
var href = "ui_page.do?sys_id=b4b2b5f7db2d1c50346fe&sysparm_rec_id=" + scTask;

window.open(href, "UPS - Print Label(s)");



}

 

Please, I really need help to get this completed.

1 ACCEPTED SOLUTION

Rajesh Kannan G
ServiceNow Employee
ServiceNow Employee

Have attached XML records for a UI Action and a UI Page. The UI Action "Print Labels" on sc_task opens the UI Page to show the images attached to current sc_task record. Follow this procedure to Import the XML records.

find_real_file.png

Regards,

Rajesh

View solution in original post

15 REPLIES 15

Rajesh Kannan G
ServiceNow Employee
ServiceNow Employee

Change j:set to j2:set and move it above g2:evalaute.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j2:set var="jvar_sysID" value="${RP.getParameterValue('sysparm_rec_id')}"/>
<!-- GLIDERECORD in JELLY -->
	<g2:evaluate var="jvar_attachments" object="true" jelly="true">
		var sysID = jelly.jvar_sysID;
		var label = [];
        var sysAttachmentGR = new GlideRecord('sys_attachment');
        sysAttachmentGR.addQuery('table_sys_id', sysID);
		sysAttachmentGR.addQuery('table_name', 'sc_task');
        sysAttachmentGR.query();
		
		while(sysAttachmentGR.next()){
		
		label.push(sysAttachmentGR.sys_id.toString());
		
		}
				
		label;
			
	</g2:evaluate>

 

This still did not work. I can see that variable in the URL, but it just isn't passing. 

find_real_file.pngIs there a way to pull it in the client script of the UI Page and then pass it that way.

Here is a sample UI Page that lists users based on a criteria passed as URL Parameter. I tested this is working in Orlando.

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<j2:set var="jvar_criteria" value="$[RP.getParameterValue('sysparm_criteria')]"/>
	<g2:evaluate object="true" jelly="true">
		var users = new GlideRecord('sys_user');
		users.addEncodedQuery(jelly.jvar_criteria);
		users.query();
		var userList = [];
		while(users.next()) {
			if(users.canRead()) {
				var user = {};
				user.name = users.getDisplayValue();
				user.mail = users.email + '';
				userList.push(user);
			}
		}
		userList;
	</g2:evaluate>
	<table style="width:100%">
		<tr><th style="width:50%">Name</th><th style="width:50%">EMail</th></tr>
		<tbody>
			<j2:forEach var='jvar_user' items='$[userList]'>
				<tr>
					<td>$[jvar_user.name]</td>
					<td>$[jvar_user.mail]</td>
				</tr>
			</j2:forEach>
		</tbody>
	</table>
</j:jelly>

Regards,

Rajesh

I did a test using your UI Page and I didn't see the parameter pass to the UI Page, when I ran it, it just gave a list of users.  I wanted to get the user with a specific sys_id, but it gave me a full list.

Could it be my UI Action?  Or am I suppose to include something in the client script of the UI Page?