- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 11:08 AM
I have an array of sys ids and I want to dynamically create a URL to view a list of these records by appending the sys ids using OR statements.
Here is what I have so far:
// sysIds will contain array of sys ids
var server_URI = gs.getProperty('glide.servlet.uri');
var url = server_URI + '/nav_to.do?uri=%2Fhr_list.do%3Fsysparm_query%3Dsys_id%';
for( i = 0; i < sysIds.length; i++) {
url += i + 'OR';
}
However, at the end of the last sys id I want to add:
'%26sysparm_first_row%3D1%26sysparm_view%3D'
How can I achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 11:28 AM
The easiest way to get the right query is in the UI itself. When viewing a list of records, use the filter and then copy the query.
When you choose Sys ID the qualifier to use is "one of"
Then when you copy the query you will get:
sys_idINb7707f7ddbb1c410d0a69875db96199e,54af6979db5fc410f73e50e4e2961977
As you can see it is using "IN" and then the ID's are separated by a comma. You can also right click on the breadcrumb and choose Copy URL:
https://INSTANCENAME.service-now.com/TABLENAME.do?sysparm_query=sys_idINb7707f7ddbb1c410d0a69875db96199e%2C54af6979db5fc410f73e50e4e2961977&sysparm_view=
Is is important to note that the order of the parameters does not matter so you could put '%26sysparm_first_row%3D1%26sysparm_view%3D' first
So back to your script given the list of sys_ids are separated by commas, with an array you can simply use the JavaScript join(",") function on the array and append it to your text string.
Please mark this post or any as helpful or the correct answer to your question if applicable so others viewing may benefit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 11:28 AM
The easiest way to get the right query is in the UI itself. When viewing a list of records, use the filter and then copy the query.
When you choose Sys ID the qualifier to use is "one of"
Then when you copy the query you will get:
sys_idINb7707f7ddbb1c410d0a69875db96199e,54af6979db5fc410f73e50e4e2961977
As you can see it is using "IN" and then the ID's are separated by a comma. You can also right click on the breadcrumb and choose Copy URL:
https://INSTANCENAME.service-now.com/TABLENAME.do?sysparm_query=sys_idINb7707f7ddbb1c410d0a69875db96199e%2C54af6979db5fc410f73e50e4e2961977&sysparm_view=
Is is important to note that the order of the parameters does not matter so you could put '%26sysparm_first_row%3D1%26sysparm_view%3D' first
So back to your script given the list of sys_ids are separated by commas, with an array you can simply use the JavaScript join(",") function on the array and append it to your text string.
Please mark this post or any as helpful or the correct answer to your question if applicable so others viewing may benefit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 02:59 PM
This is a great solution, however the Javascript join() function is not working for some reason.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 03:06 PM
thank you, this worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2021 08:58 AM
How to get the URL if the sys_ids are fetched dynamically and considering if there is a list of 200+ sys_id, the url would be long, is there a way to get the tiny url through script?