Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Passing parent URL parameters from Configurable workspace to service portal

mangeshgangarde
Tera Contributor

Hello,

I have a requirement to replicate a native UI functionality into configurable workspace. 

Once you click on the save button on the case record, it should redirect to open the service portal in a new tab and parent parameters(table name and sys_id of the parent record should be passed to the url).

mangeshgangarde_0-1677224986644.png

mangeshgangarde_1-1677225190555.png

I am able to achieve the redirection using a workspace client script on the 'Save' UI action.

 

var result = g_form.submit('sysverb_ws_save');
	if (!result) {
		//failed form submission
		return;
	}
	result.then(function() {
			var params = {};
			params.parent_table = "my_table_name";
			params.parent_sys_id = g_form.getUniqueValue();
			g_service_catalog.openCatalogItem('sc_cat_item','-1', params);		
	});
}

 

As you can see, I am passing the parameters here. But, when I try to retrieve these parameters in one of the widgets using  $sp.getParameter("parent_sys_id") on the server side, I get null value.
I tried to print the url using window.location.url and I get "https://instancename.service-now.com/swp"
which means the parameters are not getting passed to the url from UI action. 

Can anyone please help, where I am making a mistake? or any other way to achieve this in configurable workspace?
P.S. Same script works for the Agent workspace.

 

5 REPLIES 5

jayr
Tera Contributor

Same question, haven't managed to find a solution just yet.

Jessica38
Tera Contributor

Any luck on finding the solution? I have the same question.

Wybren1
Tera Guru

Hopefully this one will help out somebody if needed

I needed to get the parameter given from the "create request" into a client script, in my case the sysparm_parent_sys_id. Ofcourse I could just simply get the current record ID.

Hope this helps 😀

 

Catalog Client script on load:

function onLoad() {
   //Type appropriate comment here, and begin script below
	
	alert(getUrlParamFromWorkspace('sysparm_parent_sys_id'));
	
	function getUrlParamFromWorkspace(paramName) {
		
		var url = decodeURIComponent(top.location.href); //Get the URL and decode it
		var workspaceParams = url.split('extra-params/')[1]; //Split off the url on Extra params
		var allParams = workspaceParams.split('/'); //The params are split on slashes '/'
		
		//Search for the parameter requested
		for (var i=0; i< allParams.length; i++) {
			if(allParams[i] == paramName) {
				return allParams[i+1];
			}
		}
	}
}

 

Perfect, thanks for this - just what I needed!


In my scenario I'm selecting a list of assets to create a transfer order for with a list action in the HAM workspace, and then forwarding the user to a catalog item which grabs those selected sys_ids from the URL.