- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2017 09:20 PM
Hello all,
So I am creating a UI page that requires a select box to become populated with values that are stored inside a custom table. The custom table
has a column that contains a 'choices field' with several different choices. I am wondering if there is a way to get an array of these values into the
jelly script and use it in the select box. An example would be lovely too.
Thank you for any help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2017 02:46 PM
Here you go
<g:evaluate var="jvar_test" object="true" jelly="true">
var obj=[];
var gr= new GlideRecord('u_sales_order_ui');
gr.query();
while(gr.next()){
obj.push(gr.u_subcategory.toString());
}
obj;
</g:evaluate>
<select>
<j:forEach var="jvar_item" items="${jvar_test}">
<option value="${jvar_item}"> ${jvar_item} </option>
</j:forEach>
</select>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2017 09:36 PM
Hi Roni,
here is one example
html section of ui page
Select the fields:
<select name="dynamicColumns" id="dynamicColumns" multiple="multipe" style="display:none">
</select><br/>
client script of ui page
var select = document.getElementById('dynamicColumns');
document.getElementById("dynamicColumns").options.length=0;
var gr1 = new GlideRecord('incident');
// gr1.addQuery('column',);
gr1.query();
while(gr1.next()){
var opt = document.createElement('option');
opt.value = gr1.category;
opt.innerHTML = gr1.category;
select.appendChild(opt);
}
document.getElementById('dynamicColumns').style.display = '';
this example will create a drop down with categories present in incident table
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2017 01:48 PM
This would only work if there are elements to be able to query from in the table. But I only want the values from the choices field in category.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2017 02:13 PM
Something like this in the HTML will work
<g:evaluate var="jvar_test" object="true" jelly="true">
var obj=[];
var gr= new GlideRecord('sys_choice');
gr.addQuery('nameSTARTSWITHincident^element=category');
gr.query();
while(gr.next()){
obj.push(gr.label.toString());
}
obj;
</g:evaluate>
<select>
<j:forEach var="jvar_item" items="${jvar_test}">
<option value="${jvar_item}"> ${jvar_item} </option>
</j:forEach>
</select>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2017 02:27 PM
Hi Thanks for the response!
It seems to work for that table but how do I create a column in my table to achieve the same result. I cannot seem to find the 'category' column in 'sys_choice' to copy the same column.