Create Reference Qualifier filter with if-else statement

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 03:06 AM - edited 02-21-2023 04:08 AM
Hello,
I'm trying to create a reference qualifier that will filter based on the user's location such that if the location is anywhere in the US (location starts with US) then it will go to a particular US location. For example, if the user's location is USSF or USTX or USNY, the filter will show US. Any other location, like FR or UK will show the user's location.
Here's the ref qual filter that I created but it's not working.
javascript: var ret= '';if (current.variables.requested_for.locationSTARTSWITHUS) ret += '^location=US'; else ret += '^current.variables.requested_for.location'; ret;
Any help is appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 03:09 AM
are you applying ref qualifier on field referring to location table?
If yes then use this
javascript: var ret; if (current.requested_for.location.toString().startsWith('US')) ret = 'name=US'; else ret = 'sys_id='+ current.requested_for.location; ret;
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-21-2023 03:51 AM
@Ankur Bawiskar I'm referring to the location under alm_hardware. I tried the abovementioned script you gave, now it's coming up empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 03:57 AM
are you sure alm_hardware table has requested_for field?
Because out of the box it's not there. see below image
ensure you use the correct field which refers to user table
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-21-2023 04:04 AM
Hi, @Ankur Bawiskar
Sorry for the confusion, I'm using this on a Service Request where users request for hardware assets. Basically, if a user requests for a hardware asset, for example, a laptop, and that user is in USNY for example, then it will pull the asset from one US location. If a user is outside US, it will check the user's location (current.variables.requested_for.location) and pull the stock from the user's location. Sorry my initial script was missing the "variables".
But this one below comes up empty:
javascript: var ret; if (current.variables.requested_for.location.toString().startsWith('US')) ret = 'name=US'; else ret = 'sys_id='+ current.variables.requested_for.location; ret;