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

Add default value in Lookup select box

ServiceNow SA
Kilo Guru

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? 

9 REPLIES 9

The SN Nerd
Giga Sage
Giga Sage

Two options:

  1. Create a "Not in List" option for every possible dependent value
  2. Add the "Not in list" option by client script on load.

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

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,

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;
}

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

CharlesGriff
Mega Sage

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