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

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

Hi @ChrisBurks 

Thanks a lot for the help 😍

It was really helpful.

Hi Chris,

 

I have a glidelist field which displays list of values. i can select multiple values and with the code snippet you provided, i am not able to read them in client script. Can you please help to read the selected values in client script of ui page.

Hi@Mala Basavaraja ,

I hope you were able to figure out what you needed. I never got  a notification from your post.