Generate URL from sys_id (in script)

alinatoc
Giga Contributor

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?

find_real_file.png

ServiceNow can generate URL out of record, so I believe it can be done in script (I hope so).

Thanks in advance!

1 ACCEPTED SOLUTION

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


View solution in original post

14 REPLIES 14

Chuck Tomasi
Tera Patron

Hi Allen,



Can you shed some light on what your requirement/use case is? It's possible to generate a URL quite easily. Do you want this in a notification, UI action, or something else? There may be easier ways once I know the underlying requirement and what you are working with.


Hi Chuck,




This is for a UI action, but I'm currently writing up this portion within a Script Include (which I currently treat as class library / utility helper in script).


Currently I have this script which does quite a dirty job of generating URL of a record based on table, and sys_id (don't mind the nav_visible argument, it's an optional argument if you want to wrap the resulting content with navigation pane):


find_real_file.png


but I just thought that this won't be applicable when I have a sys_id coming from field referencing to Task table (meaning, it can be an Incident table, a KB Submission table, etc.) which would mean that I have to find a way to generate URL (through script) using only the sys_id. Is there a way in script to do this? Does SerivceNow offer an API/class to do this?


Abhinay Erra
Giga Sage

This is already there out of box. In the UI context menus search for "Copy URL to Clipboard"


Hi Abhinay,



Already mentioned that. I'm asking how do it "in scripting".