GlideSubstituteURL: The Useful Part
Ignore the noisy method list and use it for record links
If you look up GlideSubstituteURL, the method list can be distracting.
You see names like notify(), notifyAll(), wait(), hashCode(), equals(), and getClass(), and it is not obvious which part is actually relevant for day-to-day scripting.
For most ServiceNow work, the practical answer is simple:
GlideSubstituteURL is mainly about generating a URL for a record.
That means the methods most people care about are generateURL() and, in some cases, generateRelativeURL().
1. What problem this class actually solves
Sometimes a script needs to output a clickable link to a record instead of only its number or sys_id.
Typical examples are:
- notification email scripts
- generated HTML content
- server-side utilities that need to print or store a record link
That is where GlideSubstituteURL becomes useful.
Instead of hand-building the URL with string concatenation, you can let the platform generate the record link for you.
2. The main method: generateURL()
The method you will usually reach for is generateURL().
Example:
var gr = new GlideRecord("incident");
if (gr.get(incidentSysId)) {
var url = new GlideSubstituteURL().generateURL(gr, "");
gs.info(url);
}
The output is typically a full instance URL that points to the record, often in a nav_to.do?uri=... form.
That is why this class shows up often in notification scripts that print HTML anchors:
var link = new GlideSubstituteURL().generateURL(gr, "");
var anchor = "<a href='" + link + "'>" + gr.getDisplayValue() + "</a>";
template.print(anchor);
If your goal is “give me a usable link to this record,” this is the part of the API worth remembering.
3. When generateRelativeURL() is the better fit
Sometimes you do not want the full absolute instance URL.
You may only want the record path relative to the current instance, for example when another layer already knows the host name.
That is the situation where generateRelativeURL() is the more relevant method.
The practical distinction is:
generateURL()gives you the full record URLgenerateRelativeURL()gives you the relative record path
If you only need the path, using the relative form is cleaner than manually stripping the host from a full URL.
4. Why the rest of the method list is mostly noise
This is the part that confuses people.
The API listing may expose methods such as:
notify()notifyAll()wait()equals()hashCode()getClass()toString()
Those names make it look as if GlideSubstituteURL is a broad utility object with lots of behavior.
In practice, they are not the reason most developers open this API in the first place.
The useful mental model is:
- ignore the inherited-looking object methods
- focus on URL generation
- pick the narrowest method that gives you the link format you need
If the requirement is “I need a record URL,” the class stops being mysterious very quickly.
5. Do not overcomplicate record link generation
When teams do not know GlideSubstituteURL, they often build links manually:
var url = gs.getProperty("glide.servlet.uri") +
"nav_to.do?uri=incident.do%3Fsys_id=" + current.getUniqueValue();
That works, but it is harder to read and easier to get wrong.
If the platform already provides a URL helper, it is usually better to use it instead of assembling the link yourself.
The point is not that manual construction is impossible. The point is that the intent is clearer when the code says “generate a URL for this record.”
6. A practical rule of thumb
This is the bias I would keep:
- need a full record URL: use
generateURL() - need only the relative path: use
generateRelativeURL() - see
wait(),notify(),hashCode(), and similar names: treat them as noise, not as the core API
That framing keeps the class small in your head and makes it easier to explain in a code review.
Final thought
GlideSubstituteURL looks more complicated than it usually is.
Most of the visible methods are not what matter in real scripts.
The practical value of the class is straightforward: it helps you generate links to records.
If that is your use case, focus on generateURL() and generateRelativeURL() and ignore the rest of the method list unless you have a very specific reason not to.