How can I get the current record's sys_id in a UI Page?

Arshdeep Singh
Tera Contributor

So i want a select box in my glideWindow UI Page where i have to display the users that are currently in a list collector of a record.
find_real_file.png

and i want to show these two users in a select box of UI Page here:

find_real_file.png

 

currently im using this script in my 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">
<g:evaluate jelly = "true">

var gr_inc = new GlideRecord('incident');
gr_inc.addQuery('sys_id', '2bdad2b61b5c23038e2520e6e4bcbf4');
gr_inc.query();
</g:evaluate>

<div>
<h2>Please select the users</h2>
<select>
<option>--NONE--</option>
<j:while test="${inc.next()}">
<option value="${inc.sys_id}">${inc.committee_list}</option>
</j:while>
</select>
</div>

</j:jelly>

 

By passing sys_id in 2bdad2b61b5c23038e2520e6e4bcbf4 addQuery its working but i need g_form.getUniqueValue() of the record or current.sys_id of the record so that it works dynamically for every record.

Any help would be greatly appreciated.

🙂

1 ACCEPTED SOLUTION

Hi,

This worked well for me

UI Action:

function showPage(){

	var gm = new GlideModal('sn_customerservice_show_my_ui_page');
	gm.setTitle('My Page');
	gm.setSize('600', '600');
	gm.setPreference('sysparm_caseID', g_form.getUniqueValue());
	gm.render();

}

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">

    <g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().sysparm_caseID"/>

    <g:evaluate jelly="true" object="true">
        var gr_acp = new GlideRecord('sn_customerservice_case');
        gr_acp.addQuery('sys_id', jelly.jvar_sysId);
        gr_acp.query();
        gr_acp;
    </g:evaluate>

    <p>${jvar_sysId}</p>
    
    <div>
        <h2>Please select the users on behalf of which you would like to endorse the case</h2>
        <select>
            <option>--NONE--</option>
            <j:while test="${gr_acp.next()}">
                <option value="${gr_acp.sys_id}">${gr_acp.getDisplayValue()}</option>
            </j:while>
        </select>
    </div>

</j:jelly>

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you are calling the UI page from UI action you need to send the current sys_id using parameter

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

like this

var dialog = new GlideDialogWindow("approval_ui_page"); 'task_comments_dialog'
    dialog.setTitle("Create Approval");
    dialog.setPreference("sysparm_sys_id", g_form.getUniqueValue());

    dialog.render();

Then in UI page use like this

<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().get('sysparm_sys_id')" />

<?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 jelly = "true">

var gr_inc = new GlideRecord('incident');
gr_inc.addQuery('sys_id', '${jvar_sysId}');
gr_inc.query();
</g:evaluate>

<div>
<h2>Please select the users</h2>
<select>
<option>--NONE--</option>
<j:while test="${inc.next()}">
<option value="${inc.sys_id}">${inc.committee_list}</option>
</j:while>
</select>
</div>

</j:jelly>

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hey Ankur if pasted the line on top its giving me this error

find_real_file.png

And even after trying to write code in below line its still not showing me the users