How to get the UI page glide list field value in client script

Haridevan Vamad
Tera Contributor

Below is the code written on UI Page for glide list type field.

We are trying to select the value on glide list and access it in client script.

In client script while trying to access through "$j("#changeSubsystem").val()" its returning undefined.

HTML

 

<g:ui_form>
	<g:macro_invoke macro= "lightweight_glide_list" id="changeSubsystem" name="change_subsystem" reference="sys_user" can_write="true" control_name="QUERY:user_name=abel.tuter"  />
	
	<div style="padding:5px;float:right">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td align="left" nowrap="true"><br /><g:dialog_buttons_ok_cancel ok="return validateForm();" cancel="return onCancel();"/>
					</td>
				</tr>
			</table>
		</div>
	</g:ui_form>

 

Client Script

function validateForm() {
	var grList = $j("#changeSubsystem").val();
	alert(grList);
}

We even tried "document.getElementById('changeSubsystem').value;" but didnt workout

 

Screenshot of Output

HaridevanVamad_0-1701397315995.png

Could someone please help me with the above issue on how to fetch the value in client script.

 

Please Help!!!

 

Referred Community Posts and other:

How to create a Glide list field in ui page

How to add a Glide List field in a UI Page? | use-case | ServiceNow

IN UI page , how to get the glide_list type records value in UI page client script

1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

Hi @Haridevan Vamad ,

 

It doesn't work because the UI Macro "lightweight_glide_list" doesn't have any code to take the outer id attribute of the "g:macro_invoke" element and pass it to the select element once rendered. However, it does take the "control_name" attribute and concatenates it to the select "id" attribute making the id, in your example, this:

select_0QUERY:user_name=abel.tuter

Also since you're in a Jelly page you can use gel() method instead of $j() to get the value:

var selectValueElement = gel('select_0QUERY:user_name=abel.tuter');

 

So if you keep the same html markup but changed the validateForm function to this:

function validateForm(){
	var grList = gel('select_0QUERY:user_name=abel.tuter');
	var grListOptions = Array.from(grList);
	if(grListOptions.length){
		alert(grListOptions[0].value)
	}
}

 

If you select Abel Tuter (since the query is filtering to only Abel Tuter) and you click the Ok button you should see Abel Tuter's sys_id.

abel_tuters_sys_id.png

View solution in original post

7 REPLIES 7

M_48
Tera Contributor

Hi,

 

Can you please explain from where you get the select_0Query?

 

var grList = gel('select_0QUERY:user_name=abel.tuter');

Hi @M_48 ,

 

"select_0" is in the lightweight_glide_list UI Macro that is being invoked by the script posted.

"Query" is part of the parameter the poster ( @Haridevan Vamad ) is passing to the attribute "control_name" on the jelly tag "g:macro_invoke" in the script.

 

Screen Shot 2024-04-30 at 5.41.25 AM.pnglightweight_glide_list_UI_Macro.png

 

 

The lightweight_glide_list code replaces the "g:macro_invoke" tag when the page renders and uses some of the parameters supplied to its attributes like the "Query:user_name=abel.tuter" passed to the "control_name" attribute.

M_48
Tera Contributor

Thanks for your reply.