Using \$cookies with Service Portal Widgets

krr
Mega Guru

I have created a Service Portal Widget that I use to lookup an item. I then set this to a cookie in AngularJS using

$cookies.put('mycookie', 'myvalue');

I am hoping to use this cookie in various other widgets during a session on the Service Portal.

The trouble I'm having is I cannot figure out if it's possible to read this cookie on the server code of the the widget.

Is this possible? If not, is there another method that makes it easy to keep data in a "session" that can be accessed on the server side of the widget?

The only option I've found that is reliable is to create a temporary table that stores this value for the particular session and read from there, any better options than that?

1 REPLY 1

Miriam Berg
Kilo Guru

Hi there,



Was wondering the same thing, and found this article: Session client data


It basically says that you can use ServiceNow functions to set / get /clear client session data using the functions



putClientData(name, value);


getClientData(name);


clearClientData(name);



From a server script, call the function like this:



gs.getSession().putClientData('variable_name1', 'value1');



and then get it from the client like this:



var value = g_user.getClientData('variable_name1');



Best Regards,


Miriam