how to add choice options from another table dynamically on an ui page

hemanth_alapati
Mega Contributor

how to add options to a choice list/drop down dynamically from table in an ui page.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Hemanth,

can you share your code here? also from which table and what field you want to fetch

you can use html select tag to create drop down based on the choice values

sample script here

for example I have used incident table and state column

<g:evaluate var="jvar_gr" object="true">

var gr = new GlideRecord('sys_choice');

gr.addQuery('element', 'state');

gr.addQuery('name', 'incident');

gr.quey();

gr;

</g:evaluate>

<select>

<j:while test="${jvar_gr.next()}">

<option value="${jvar_gr.value}">${jvar_gr.label}</option>

</j:while>

</select>

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Hemanth,

can you share your code here? also from which table and what field you want to fetch

you can use html select tag to create drop down based on the choice values

sample script here

for example I have used incident table and state column

<g:evaluate var="jvar_gr" object="true">

var gr = new GlideRecord('sys_choice');

gr.addQuery('element', 'state');

gr.addQuery('name', 'incident');

gr.quey();

gr;

</g:evaluate>

<select>

<j:while test="${jvar_gr.next()}">

<option value="${jvar_gr.value}">${jvar_gr.label}</option>

</j:while>

</select>

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur,

 

thanks for the response. i wanted to fetch from a custom table that is created in our instance. i wanted to set the choice values based on the value selected in a particular field. 

i will try the soultion given by you and let you know.

 

thanks,

hemanth

There is a typo where says "gr.quey();" is gr.query(); instead. 

 

Thanks

Avinash_Patil1
Giga Guru

@Ankur Bawiskar  this is not working for me I am getting just dropdown Icon on the UI page.find_real_file.png 

Could you plz help in this?