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

Hi,

this line should be inside the jelly

Also I assume you are sending the parameter from UI action to this UI page so you must have added like this

    dialog.setPreference("sysparm_sys_id", g_form.getUniqueValue());

so update as this

<?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().get('sysparm_sys_id')" />


<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

Hi Ankur this is my code:

UI Action:

function showCommitteeUsers()
{
var gm = new GlideModal('x_adsr_endorse_for_member');
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().get('sysparm_caseID')"/>
<g:evaluate jelly = "true">
var gr_acp = new GlideRecord('x_adsr_acp');
gr_acp.addQuery('sys_id','${jvar_sysId}');
gr_acp.query();
</g:evaluate>

<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('committee_selection_list')}</option>
</j:while>
</select>
</div>

</j:jelly>

 

But im still not able to see the values in Select Box

find_real_file.png

😞

So you are using scoped application

try to update as this

<?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" value="${RP.getWindowProperties()['sysparm_caseID']}"/>
<g:evaluate jelly = "true">
var gr_acp = new GlideRecord('x_adsr_acp');
gr_acp.addQuery('sys_id','${jvar_sysId}');
gr_acp.query();
</g:evaluate>

<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('committee_selection_list')}</option>
</j:while>
</select>
</div>

</j:jelly>

Regards
Ankur

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

find_real_file.png

Now its completely gone.

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