- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 03:16 PM
I'm creating a mailscript to add an hyperlink that contains a sys_id provided by my trigger event.
I want the hyperlink to open the form and prefill a bucketlist field with the corresponding item with the sys_id.
I've read that in order to open the form with a prefilled field, I need to construct my url and add a "sysparm_query" as "&sysparm_query=u_list_to_install=<sys_id>" as the code below shows.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var url = "https://<instance>.service-now.com/sp?id=sc_cat_item&sys_id=b23dc73997632910bd8df92ef053af1f&sysparm_category=f93da353a77b9950c92d0b7fb05a5766";
url += "&sysparm_query=u_list_to_install=" + event.parm2;
template.print('<a href="' + url + '">Request install</a>');
})(current, template, email, email_action, event);
Somehow the url gets generated, but the field does not get populated once I click the link. Here, u_list_to_install is my bucketlist variable. Event.parm2 is my item sys_id.
Thank you for any insight you may provide.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 04:12 PM - edited 01-09-2024 04:13 PM
You can append url with &sysparm_list_to_install=event.parm2
And in your catalog, you need an onLoad script to parse this parameter.
function onLoad() {
var link = window.location.href;
var hash = link.split('&');
var parm = '';
for (var i=0;i<hash.length;i++)
{
if (hash[i].indexOf('sysparm_list_to_install')>-1)
{
parm = hash[i].split('=');
g_form.setValue('u_list_to_install',decodeURI(parm[1].toString()));
}
}
}
sysparm_query may work on tables but not on catalogs.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 04:12 PM - edited 01-09-2024 04:13 PM
You can append url with &sysparm_list_to_install=event.parm2
And in your catalog, you need an onLoad script to parse this parameter.
function onLoad() {
var link = window.location.href;
var hash = link.split('&');
var parm = '';
for (var i=0;i<hash.length;i++)
{
if (hash[i].indexOf('sysparm_list_to_install')>-1)
{
parm = hash[i].split('=');
g_form.setValue('u_list_to_install',decodeURI(parm[1].toString()));
}
}
}
sysparm_query may work on tables but not on catalogs.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 06:49 AM
It seems that window.location is no longer supported in service portal according to other posts. Is there an alternative to find the page url?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 09:28 AM
Can you try this.location.href?
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 07:36 AM
This works in service portal!
Thank you for your assistance.