How can we do passing session variables to a service portal and get those values auto populate to catalog item variables via catalog client script

Raj26
Kilo Contributor

Hi,

I have a requirement to auto populate session variables such as customer details (name, phone number etc) from a case to a catalog item variable in the service catalog portal.

We have tried below actions on the same.

 

There is a UI action, which will redirect the page to the service portal where agent can create a request by selecting the required catalog items. So we collected the session variables in the UI action and passed it.

Used session.putClientData() to do this.

From a catalog client script, we used g_user.getClientData() method to retrieve the session data and tried to print it.

This is working well and good in the Service Catalog UI and but not working in Service portal.

Any ideas on how we can do it...

Much appreciated for the responses.

Thanks,

Raj

4 REPLIES 4

Alikutty A
Tera Sage

Hello,

Can you try to pass the parameters in URL and see if it works on portal? Append your parameters at the end of URL eg:  Portal URL?sysparm_user=12345555

On the catalog item, add an on Load client script and fetch its value

function onLoad() {
var user = getParameterValue('sysparm_user');
if (user) {
g_form.setValue('requested_for', user);
}

function getParameterValue(name) {
var url = document.URL.parseQuery();
if (url[name]) {
return decodeURI(url[name]);
} else {
return;
}
}

 

Raj26
Kilo Contributor

Hi Alikutty,

Thanks for your response.

Currently, we are trying to pass the id in the URL, however, from the home page, when we click on the Service catalog item, URL is changing and the id also getting removed from the URL.

To consider your suggestion, mostly I may need to customise the widget and try to pass the id again to the new page.

Just wondering that is there an alternate way to get the g_user glidesession object in catalog client script so that it will work from the service portal.

Thanks,

Raj

Devyani_6
Mega Guru

Hi,

Go through below link, this may help you.

UI Action to pass reference field to record producer

You may apply the same logic to the service portal.

Mark Correct/Helpful, if this helps you.

Regards,

Devyani

Raj26
Kilo Contributor

Hi Devyani,

 

Thanks for your response.

We have tried similar code already. However, it worked well in the service catalog UI but not in portal.

Also we dont want to pass the variables in the URL.

Hence we are trying with session clientdata.

However we are having some difficulty in this one as well. Because the client data is showing as undefined in the portal client script.

please refer my comments on the below link.

https://community.servicenow.com/community?id=community_blog&sys_id=18ac2225dbd0dbc01dcaf3231f9619e3

 

Thanks,

Raj