The CreatorCon Call for Content is officially open! Get started here.

How to get List of possible options on choice variable field?

Zod
Giga Guru

HI,

I have a select box variable and 'remove' some options via a catalog client script on load. 

Now I need to be possible to list the remaining "possible" options via a catalog client script.

How to?

Was was hoping it works this way ... 

 

var values = [];

var sel = g_form.getElement('<variablename>');

for (var i=0, n=sel.options.length;i<n;i++) {

gs.info(sel.options[i].value);

}

.. but this seems not to work.Type Error ...  "sel is undefined" ... 

Any idea?! Thank you! 

14 REPLIES 14

Forgot to think about service portal.  However I'm still not sure why you want to try and get what is still available after doing remove option.

I do not know what option(s) will be left at the end and need to pre-set the option of only one is left. Unfortunately ServiceNow does not provide this very logical option (set value automatically if only one possible) out of the box. So I need to find a way ... . If you have better solution - I would be happy you tell me 🙂

I'm not sure.  As using the script other then not working on service portal looks a the variable and it options.  It does not know that a another script removed some options so it will still return all of them to you.  Is there no way to know from your script the removes options that it removed all but one?  Since you know how many you start wouldn't you be able to tell how many got removed?  If you could then you would be able to also do a g_form.removeOpation('variablen name', '') which would remove the none default it to the only thing in the list.

performance wise not really an option to go ... at least does not look like a professional way to go ...

Willem
Giga Sage
Giga Sage

For anyone looking to get the choice options available for a field that is supported by (Catalog) client script and works in Service Portal/Mobile:

https://community.servicenow.com/community?id=community_article&sys_id=0bff52e91b0620901e579979b04bc...