Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to fetch and set reference value using jelly

Streamline Cam
Tera Contributor

Hi! I am trying to take a field value from the form and use this to populate a field on a UI page with that value.

But it is not setting/getting the value. If i make my tags $[] I get a black reference value but if I use ${} I get no reference at all, I want to take the value from the record that is already populated.

<g2:evaluate var="jvar_cmdb_id" jelly="true">
        var val = current.getValue('cmdb_ci');
        val;
</g2:evaluate>

<g:ui_reference label="configuration_item" name="configuration_item" table="cmdb_ci" field="name" value="$[jvar_cmdb_id]" displayvalue="Testing" />
1 ACCEPTED SOLUTION

@Streamline Cam 

since you are in scoped app try this

<g:evaluate var="jvar_ci_sys_id" expression="RP.getWindowProperties().sysparm_ci_sys_id" />
                    <g:evaluate var="jvar_ci_display" expression="RP.getWindowProperties().sysparm_ci_display" />

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

10 REPLIES 10

Tushar
Kilo Sage
Kilo Sage

Hi @Streamline Cam -

 

can you please try below and if it works -

 

<g2:evaluate var="jvar_cmdb_id" jelly="true">
    var gr = new GlideRecord('cmdb_ci');
    if (current.cmdb_ci) {
        gr.get(current.cmdb_ci);
        jvar_cmdb_id = gr.getDisplayValue(); // Get the display name instead of sys_id
    } else {
        jvar_cmdb_id = "";
    }
</g2:evaluate>

<g:ui_reference 
    label="Configuration Item" 
    name="configuration_item" 
    table="cmdb_ci" 
    field="name" 
    value="${jvar_cmdb_id}" 
    displayvalue="${jvar_cmdb_id}" />

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

Thanks for taking a look Tushar!

Sadly with that code I get nothing shown in my ui button ui page:

value="${jvar_cmdb_id}"
<g:ui_reference label="Configuration Item" name="configuration_item" table="cmdb_ci" field="name" value="${jvar_cmdb_id}" displayvalue="${jvar_cmdb_id}" />

Screenshot 2025-03-07 091922.png

If I change the value variable to look like this, I see the reference i icon but it's not the correct value:

value="$[jvar_cmdb_id]"
<g:ui_reference label="Configuration Item" name="configuration_item" table="cmdb_ci" field="name" value="$[jvar_cmdb_id]" displayvalue="${jvar_cmdb_id}" />

Screenshot 2025-03-07 092013.png

@Streamline Cam 

do this for getting sysId and then another evaluate tag for display value

<g:evaluate var="jvar_sysid" object="true">
var sysId = current.getValue('cmdb_ci');
sysId;
</g:evaluate>


<g:evaluate var="jvar_displayvalue" object="true">
var sysId = current.getDisplayValue('cmdb_ci');
sysId;
</g:evaluate>

<g:ui_reference label="Configuration Item" name="configuration_item" table="cmdb_ci" field="name" value="${jvar_sysid}" displayvalue="${jvar_displayvalue}" />

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Streamline Cam 

how are you calling the UI page?

You can use this logic to set the reference field in UI page, pass the display value as well

Recently I shared working solution for this

UI action popup reference value is coming as NULL 

Send the sysId and display value as well and set both

function showModal() {
    var gm = new GlideDialogWindow('showchangerequest');
    gm.setTitle('My UI page');
	gm.setSize(600,600); //Set the dialog size

    gm.setPreference('sysparm_changesysid', g_form.getValue('caused_by'));
	gm.setPreference('sysparm_changenumber', g_form.getDisplayBox('caused_by').value);
    gm.render();
}

Please enhance from your side.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<html>
    <g:ui_form> 
        <g:evaluate var="jvar_changeSysId" expression="RP.getWindowProperties().get('sysparm_changesysid')" />
		<g:evaluate var="jvar_changenumber" expression="RP.getWindowProperties().get('sysparm_changenumber')" />
        <input type="hidden" id="changerequest1" name="changerequest1" value="${jvar_changeSysId}"></input>
        <div id='mydiv3'>
            <label id='label3'>Change Request</label>
			
			<g:ui_reference name="changerequest" id="changerequest" table="change_request" value="${jvar_changeSysId}" displayValue="${jvar_changenumber}" style="width:180px"/>

        </div>
    </g:ui_form>
</html>
</j:jelly>

Output:

AnkurBawiskar_0-1741342023551.gif

 

I hope I have answered your question and you can enhance it further

If my response helped please mark it correct and close the thread so that it benefits future readers.

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