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

How to add a Reference qual condition via an Onchange Client Script

Magali Legaspi
Tera Contributor

Hi all.

 

I'm having trouble with this. What I need to do is with an onchange client script, I have to add a Reference qual condition on a field that references the user table, that will change depending on the user's selection on another field.

 

Is this possible, to add a reference qualifier condition via Catalog Client Scripts? if so if you could give me an example.

 

Thanks in advance!!

1 ACCEPTED SOLUTION

For future users with a similar requirement, my solution was:

 

Script Include returns reference qualifier string e.g. "sys_idINx,y,z".

On the reference field, Type Specifications > Use reference qualifier > Advanced.

In the Reference qual field: 

 

javascript: new ScriptIncludeName().FunctionName();

 

 

Example:

 

javascript: new PositionUtils().getPeopleLeaderUsersRefQual();

 

 

Note: Replace : with an actual colon. Comment keeps mangling the character.

View solution in original post

8 REPLIES 8

Arav
Tera Guru

Hi,

 

What you need is this.

 

a. Create an onChange client script on the field (Field 1), which will be changed by user's selection.

 

b. Make a GlideAjax call to a Script include function by passing the changed value of Field 1 to compute the value of Field 2 (user reference).

 

c. Return the value of Field 2 back to the client script. Use that to set the value in form.

 

Thanks,

Arav

This is assuming you want to set a value in Field 2 when Field 1 changes. But if it's about just a reference qualifier change, then you may want to check the approach suggested by Laszlo.

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

No, you don't need a catalog client script for that. You need an Advanced Reference Qualifier and a script include, as described here in docs.

You can pass the value of your dependant variable as a parameter to a function in your script include which can do the "math" and return an encoded query string.

Can you elaborate on 


@Laszlo Balla wrote:

No, you don't need a catalog client script for that. You need an Advanced Reference Qualifier and a script include, as described here in docs.

You can pass the value of your dependant variable as a parameter to a function in your script include which can do the "math" and return an encoded query string.


I've been trying to achieve setting an advanced qualifier on a reference field based on the input of a previous field, in this case 'manager_requesting'.


I have a script include that returns an encoded query that looks like "sys_idINx,y,z". I tried applying that via client script without success. I tested with applying to the reference qualifier but no luck. Can you clarify the intended syntax for passing a value from a catalog item form in the portal to the script include?

Also can you confirm this will update dynamically if the value of manager_requesting changes while the user is completing the form?