Add default value in Lookup select box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2019 01:30 AM
Hi Team,
In my catalog, we want to always show a "Not in List" option in lookup select box (Var1) as the first option.
Now that Var1 is dependent on Var2(another lookup select box) .The dependency is set through script include and reference qualifier.
I am trying to achieve through onChange client script of Var2 and using g_form.addOption but it is not working.
Any idea?
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2019 01:48 AM
Two options:
- Create a "Not in List" option for every possible dependent value
- Add the "Not in list" option by client script on load.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2019 02:43 AM
For your second option to add option on Load.
That is working.. but only when the form load.But if i change value of "Var2", then it is not showing,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2019 03:21 AM
You are going to have to use on on change script also not just on load in fact I would just an on change client script because you can change the script to function on load also.
This will make the on change script also run on load.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2019 05:52 PM
Yeah sorry you will need to make is onChange with the onLoading check excluded
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2019 01:56 AM
Hi,
I think you are going to have to do something else here because a lookup select box is similar to a reference field that functions a bit differently, you can have dependencies on this field but it still returns what is already on a table that you are referencing. In my mind logically you would need to build a value before you reference it. If you use a normal select box and build your options through the script that might work.
Regards,
C