Email URL with ampersand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 10:05 AM
I can't for the life of me get a simple link to work in a mail script.
var prefix = "<a href='" + gs.getProperty('glide.servlet.uri');
var main = "/acs?id=public_survey&instance_id=" + current.sys_id;
var last = "'>Click here to take your survey</a>";
template.print(prefix + main + last);
This produces the url: https://instance.service-now.com/acs?id=public_survey&instance_id=3fdb0cd61b3df3009830433fbd4bcb4e
The link doesn't work with & in it. When I update the link to just &, the link works great.
I tried using var main = "/acs?id=public_survey%26instance_id=" + current.sys_id; but that doesn't work, either.
How do I force the ampersand to stay exactly as it is in my link?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 10:20 AM
Hi,
Try encodeURI() function to build your URI in mail script.
https://www.w3schools.com/jsref/jsref_encodeuri.asp
Thanks,
Nitin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 10:31 AM
Hi,
I tried
var prefix = "<a href='" + gs.getProperty('glide.servlet.uri');
var main = "/acs?id=public_survey&instance_id=" + current.sys_id;
var last = "'>Click here to take your survey</a>";
var fullUrl = encodeURI(prefix + main + last);
template.print(fullUrl);
And it resulted in the & becoming & instead which makes the URL broken.
https:/instance.service-now.com//acs?id=public_survey&instance_id=3fdb0cd61b3df3009830433fbd4bcb4e

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 11:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2021 02:22 PM
I have the same problem, when generating a link from a mail script that has an & ampersand ServiceNow automatically re-writes the url to be & instead.
I also tried encodeURI and encodeURIComponent neither work.
Has anyone figured out a solution to this? At this point i've wasted so much time on this I could have built my own script to insert an email to the sys_email table that won't re-write my url's to have & in them....