- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:36 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:50 AM
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;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 04:50 AM
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;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 05:26 AM
Worked perfectly, thank you!