Prefill bucket list fieldin service portal form - from url in mailscript

GabrielCSSMI
Tera Contributor

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.

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

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.

View solution in original post

4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

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.

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?

Can you try this.location.href?


Please mark this response as correct or helpful if it assisted you with your question.

This works in service portal!

 

Thank you for your assistance.