- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2021 10:25 AM
Hello,
I have a portal widget, and in my portal widget, I have a dropdown field that needs to dynamically display choices from a field in ServiceNow. How can I do this?
For Example: On the Incident form, I would like to display the choices in the state field in a dropdown through my widget on the portal.
My portal experience is new so anything helps.
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2021 11:19 AM
Here is a very simplified example that you can examine:
HTML
<div>
${States}
<sn-choice-list field="snChoice" sn-model="c.state" sn-options="data.states" sn-value-field="value" sn-text-field="label" sn-items="data.states"></sn-choice-list>
</div>
Server Script:
(function() {
//create a place in the data object to hold your values
data.states = [];
//query your values
var inc_states = new GlideRecord('sys_choice');
inc_states.addEncodedQuery('element=state^nameSTARTSWITHincident');
inc_states.query();
while (inc_states.next()) {
//push your values to the data object
var stateObj = {};
stateObj.label = inc_states.label.toString();
stateObj.value = inc_states.value.toString();
data.states.push(stateObj);
}
})();
That should be all you need 🙂
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2021 11:19 AM
Here is a very simplified example that you can examine:
HTML
<div>
${States}
<sn-choice-list field="snChoice" sn-model="c.state" sn-options="data.states" sn-value-field="value" sn-text-field="label" sn-items="data.states"></sn-choice-list>
</div>
Server Script:
(function() {
//create a place in the data object to hold your values
data.states = [];
//query your values
var inc_states = new GlideRecord('sys_choice');
inc_states.addEncodedQuery('element=state^nameSTARTSWITHincident');
inc_states.query();
while (inc_states.next()) {
//push your values to the data object
var stateObj = {};
stateObj.label = inc_states.label.toString();
stateObj.value = inc_states.value.toString();
data.states.push(stateObj);
}
})();
That should be all you need 🙂
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2021 11:45 AM
This worked. Thanks!