Add more than one IF statement to a Reference Qualifier

Wayne Miller
Tera Guru

I have a requirement to filter results in a reference field (cmn_location) based on values in another variable.   We have four possible filter outcomes and I'm trying with the below:

 

javascript:if(current.variables.which_psc=='psc_north')'u_sap_psc_north=true';if(current.variables.which_psc=='psc_central')'u_sap_psc_central=true';if(current.variables.which_psc=='psc_south')'u_sap_psc_south=true';else'active=true';

 

This works for only ONE if statement, but adding two more before the ELSE statement is what I need. 

 

This works:

javascript:if(current.variables.which_psc=='psc_north')'u_sap_psc_north=true';else'active=true';

 

Put simply, I need this:

 

If A = then show filter A

If B = then show filter B

If C = then show filter C

Else show all

 

Can I do this in reference qualifier or will I have to use Script Include?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Wayne Miller 

try this and no script include required, the complete ref qualifier fits into the field

javascript:var val = current.variables.which_psc; 
if(val =='psc_north') query = 'u_sap_psc_north=true'; 
else if(val == 'psc_central') query = 'u_sap_psc_central=true'; 
else if(val =='psc_south') query = 'u_sap_psc_south=true'; 
else query = 'active=true';
query;

AnkurBawiskar_0-1739883029884.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Viraj Hudlikar
Tera Sage

Hello @Wayne Miller 

 

The best way is to call a script include and move your if-else and rest of the logic there

javascript: new ScriptIncludeName().functioNameName()

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Ankur Bawiskar
Tera Patron
Tera Patron

@Wayne Miller 

try this and no script include required, the complete ref qualifier fits into the field

javascript:var val = current.variables.which_psc; 
if(val =='psc_north') query = 'u_sap_psc_north=true'; 
else if(val == 'psc_central') query = 'u_sap_psc_central=true'; 
else if(val =='psc_south') query = 'u_sap_psc_south=true'; 
else query = 'active=true';
query;

AnkurBawiskar_0-1739883029884.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Worked perfectly, thank you!