How to pass data from one Service Portal page to another?

Candon Needham
Kilo Explorer

Hi,

I'm currently setting up a Service Portal, and I would like to be able to pass some data from page to page. On the Homepage I have a drop-down where the user can pick a project they are on and product that they own, and then they click a button that takes them to another page to choose a Catalog Item. I would like to pass the Project and Product selections over to the next page so that I can use it to filter down the Catalog Items that the user sees. I believe I can pass those values within the page URL but I'm not familiar with how to do that. Any suggestions would be appreciated.

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

you may use Angular rootScope to pass data as an option

 

 

 

however there is data object that is being passed from server to client: Widget scripting

 

 

 

may be used in your case as well ..

 

 

 

For Example:

 

 

 

Server script should write something like

 

data.user_id = gs.getUserID();

 

 

Client script of widget will ready this info:

 

$scope.data.user_id;

 

Regards,

Sachin

Christian Graab
Giga Expert

When you click the button fire an event like this in you client scriot: 

function ($scope, $window) {
    var c = this:

    c.onClick = function () {
        $window.location.href = "/sp?id=new_widget&variable=" + variable;
    }
}

this redirects you to new_widget page with the parameter variable.

 

On the server-side script of the catalog item, you can get the parameter like: 

var variable = $sp.getParameter('variable');

Best regards, 
Chiristian

Omkar Mone
Mega Sage

Hi 

You can use $location.search(); by defining the $location in the client script.

Prabhat Mishra
ServiceNow Employee
ServiceNow Employee

Hi Candon,

This is what you need to do.

  1. First you need to hook into the page navigation event to append your parameters in the url.
  2. Read those new parameters on the Catalog Item widget’s server script ( or client script),
  3. Use it to filter your items.

#1. On homepage, put this code in the Drop-down widget's Client Script. (Dont forget to add '$window' up there as dependency, shown below). Make sure you pass the projectValue and productValue in below code.

var deregisterListener = $rootScope.$on('$locationChangeStart', function (event, next, current) {
		event.preventDefault();
		var q = '&project=' + encodeURI(projectValue) + '&product=' + encodeURI(productValue);
		$window.location.href = next + q;
		deregisterListener();
	});
function($window) {
	var c = this;
	.
	.
	.

#2. In SC Catalog Item widget, add this code in Server Script. (in case you want to add in Client script, just google or let me know.)

var myProject = $sp.getParameter("project"),
			myProduct = $sp.getParameter("product");

#3. Use myProject and myProduct to filter the Catalog Items.

 

Regards,

Prabhat