Reference qualifier

servicenow_devo
Tera Expert

How can we script a variablr reference qualifier to show variable drop down only if depended value is not empty. Eg-variablr should show user assigned assets based on username. Currently without selecting user name all assets are showing it should be empty if no user name selected. 

Ps - we are not aiming to use ui policy to make readonly 

Thankyou
3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Does your Reference qualifier look similar to this

BradBowman_0-1705411550003.png

or are you calling a Script Include and function that is returning a list of sys_ids?

Thanks Brad for reply.

The qualifier looks similar with calling function inside script including and passing current variablr from catalog

Thankyou

OK, so then in the Script Include just be sure to return an empty list if the argument passed into the function is empty.  I usually do this by declaring an empty array at the beginning

var answerArr = [];

then the GlideRecord pushes sys_ids from the target table into the array for records that match the argument (assets belonging to a user in your case).  Wrap your GlideRecord in an if block to only execute if the argument is not blank so that it doesn't return all assets without an assigned user, if you don't want to see those.  Then when the joined array is returned with something like this

return 'sys_idIN' + answerArr.join(',');

you'll be returning sys_idIN blank in this case, instead of a list of records that you didn't want, or if you have it coded differently, returning nothing, or something that the qualifier can't interpret, which results in showing all of the records.