Pass parameter through the URL in service portal to the record producer.

Varsha21
Giga Guru

Hello Experts,

I have a widget, in (icon link)widget, I have provided the URL of the record producer in the widget at the server-side, so after clicking on this it is redirecting to the Record Producer ABC.

like : data.href=gs.getProperty('glide.servlet.uri')+gs.getProperty('Portal suffix')+"sys_id of record producer";

but I want to send some extra parameter from this URL like '&sysparm_dept=XYZ'

and want to capture this in the record producers variable.

so if the variable contains "XYZ" I want to populate some more variables using client script.

Can you please help me with the same?

Please share the thoughts and how to achive this ? which way is a better way to achieve this?

 

Thanks

 

 

 

 

 

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

For Service Portal, you could add an onLoad Catalog Client Script to your Record Producer. onLoad Catalog Client Script which code like for example:

function onLoad() {

	var value = getParameterValue('sysparm_test');
	if(value) {
		g_form.addInfoMessage(value);
	}

}
function getParameterValue(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(top.location);
	if (results == null) {
		return "";
	} else {
		return unescape(results[1]);
	}
}

In this case, I just added to the URL:

find_real_file.png 

This would give me:

find_real_file.png

The example is just with a g_form.addInfoMessage. Though obviously you could use g_form.setValue etc..

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

2 REPLIES 2

Mark Roethof
Tera Patron
Tera Patron

Hi there,

For Service Portal, you could add an onLoad Catalog Client Script to your Record Producer. onLoad Catalog Client Script which code like for example:

function onLoad() {

	var value = getParameterValue('sysparm_test');
	if(value) {
		g_form.addInfoMessage(value);
	}

}
function getParameterValue(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(top.location);
	if (results == null) {
		return "";
	} else {
		return unescape(results[1]);
	}
}

In this case, I just added to the URL:

find_real_file.png 

This would give me:

find_real_file.png

The example is just with a g_form.addInfoMessage. Though obviously you could use g_form.setValue etc..

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hello Mark,

Thank you for the quick reply,

But after clicking on the URL

Server script : data.href=gs.getProperty('glide.servlet.uri')+gs.getProperty('Portal suffix')+"sys_id of record producer"+'&sysparm_test=hello';

i can't see the 'sysparm_test=hello' additional parameter in the URL after opening.

So in the OnLoad script, I am not getting any value.

Can you please guide me on the same?

 

Thanks.