- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 08:54 AM
Hi everybody,
I tried to look into sections of API documentation where I can possibly find the answer, but failed to find the answer.
So how do you get the URL to a record through it's sys_id? Is it possible? What class/function does ServiceNow offer to do this?
ServiceNow can generate URL out of record, so I believe it can be done in script (I hope so).
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:12 AM
Hi Chuck,
Chuck Tomasi wrote:
If you have the table name and sys_id, then the URL is a simple matter of putting the pieces together.
var url = "/" + table_name + '.do?sys_id=' + sys_id;
For example, a specific incident record can be addressed like this:
/incident.do?sys_id=90431616dbe222002e38711ebf9619f7
I already have this, and doable with gs.generateURL(tablename, sys_id)
The reason why I asked that is because I have a field that references to Task table (and therefore, can be filled with sys_id coming from tables: Incident, Service Request, Problem, etc. and that makes it difficult to generate URL from that field.
But I think I've figured out the solution myself now: I just get the value of Number field from the referenced Task record, check the prefix of Number (if it starts with TASK, INC, PROB, etc.) and that's where my script can conclude the table name.
Thanks to your responses

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 09:43 AM
My bad, I have overlooked that. So you want to know the table name when you have sys_id, is that what you want?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 09:57 AM
Hi Abhinay,
My bad, I have overlooked that.
No worries.
So you want to know the table name when you have sys_id, is that what you want?
Possibly, yes. Can be an alternative part of the solution. My main goal is to generate URL to the record using the record's sys_id alone.
But if a way to find the table name out of a sys_id can also be a good alternative solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 12:30 PM
Hi Allen,
Getting a table name when all you have is a sys_id is not possible unless you go through the entire 2000+ tables and query for a match. I don't recommend this approach as it's inefficient and may lead to performance issues.
If you have the table name and sys_id, then the URL is a simple matter of putting the pieces together.
var url = "/" + table_name + '.do?sys_id=' + sys_id;
For example, a specific incident record can be addressed like this:
/incident.do?sys_id=90431616dbe222002e38711ebf9619f7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:12 AM
Hi Chuck,
Chuck Tomasi wrote:
If you have the table name and sys_id, then the URL is a simple matter of putting the pieces together.
var url = "/" + table_name + '.do?sys_id=' + sys_id;
For example, a specific incident record can be addressed like this:
/incident.do?sys_id=90431616dbe222002e38711ebf9619f7
I already have this, and doable with gs.generateURL(tablename, sys_id)
The reason why I asked that is because I have a field that references to Task table (and therefore, can be filled with sys_id coming from tables: Incident, Service Request, Problem, etc. and that makes it difficult to generate URL from that field.
But I think I've figured out the solution myself now: I just get the value of Number field from the referenced Task record, check the prefix of Number (if it starts with TASK, INC, PROB, etc.) and that's where my script can conclude the table name.
Thanks to your responses
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2019 02:36 AM
Hello Alinatoc,
There is no need to write a separate script to find out the table name from the Prefix of the 'Number'.As you told that your required table is extended from task table you can query like this to find the name of your table from sys_id.
var ga = new GlideRecord('task');
ga.get('SYSID OF YOUR RECORD');
var Table_Name = ga.sys_class_name;
This will give you the name of the required table so that you can generate ur required url using the gs.generateURL('tablename','tablesysid') property.