How to insert an array to the Option value of a Dropdown in an UI page?

Subhashree3
Giga Contributor

Hi All,

I have one requirement where I need to push some elements to an array and that array will be sent to the Option value of the dropdown list. I am able to form the array but stuck at pushing that array to the dropdown list option in the UI page. If someone has implemented this in an UI page, please post your suggestions. 

Thank You.

 

1 ACCEPTED SOLUTION

You have to store them in array and then using for loop you will set it.. 

 

here is the sample code which i tried on my instance. just make the changes based on your need. 

 

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

		var gr = new GlideRecord('incident');
		gr.addQuery('sys_id','d41f0e10db29b300e4d95740cf9619fa'); //sys_id of an user
		gr.query();
		var userList =[];
		if(gr.next()){
		var gr2 = new GlideRecord('sys_user');
		gr2.addQuery('sys_id',gr.caller_id);
		//gr2.addQuery('u_site',gr.u_site);
		gr2.query();
		while(gr2.next()){

		userList.push(gr2.department.id);
		}

		}
		userList;

	</g:evaluate>
	
	
	
	<select id="ur">


		<option value="">-- None --</option>


		<j:forEach items="${jvar_ur}" var="jvar_array_item">   


			<option value="${jvar_array_item}">${jvar_array_item}</option>


		</j:forEach> 


	</select>

	


</j:jelly>

 

 

View solution in original post

6 REPLIES 6

Thank you. Its perfect! 🙂

I had to comment <j:while test="${jvar_grec.next()}"> this line of code of mine and compared with your code. It worked fine.

glad it helped.