How to get URL suffix of Service Portal in Service Catalog

masateru_tomiok
Kilo Expert

We are using multiple Service Portals.

I want to get the URL suffix of Service Portal (ex: sp) when catalog item is requested from only the Service Portal.
I am trying to get the URL suffix using "onSubmit" client script of Variable Set.

  • How can I judge whether catalog item is requested from Service Portal using client script?
  • Can I get the URL suffix from the Variable Set's client script?
5 REPLIES 5

Ripu Daman1
Tera Expert

You may use below line of code(server script) to get the current Service Portal suffix:

$sp.getPortalRecord().getDisplayValue("url_suffix");

Returns: URL Suffix of Portal the user is currently logged in.

 

I set up catalog client script "onSubmit" and described below code.

 

function onSubmit() {

	var urlSuffix = '';

	if (window == null) {
		urlSuffix = $sp.getPortalRecord().getDisplayValue("url_suffix");
	} else {
		urlSuffix = 'Expert Window';
	}

	g_form.setValue('url_suffix', urlSuffix);

}

But, Browser return following error: 
(g_env) [SCRIPT:EXEC] Error while running Client Script "onSubmit": ReferenceError: $sp is not defined

 

I think that $sp object can not be used in Catalog Client Script.
https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/build/service-portal/concept/unsupported_client_scripts.html

 

$sp object is available only for server side scripts. I assume you need url suffix in a widget, in that case you can iuse the data object to pass variables to your client script. For some reason, in case client has updated data model and you want to pass data to server then you can use c.server.update().

This article might be helpful: Available Variables in client/server 

Deepak Negi
Mega Sage
Mega Sage

Hi

You can simply use $sp.getValue('url_suffix') on server script of the widget.

 

Thanks

Deepak