Using \$cookies with Service Portal Widgets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 11:54 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2017 04:31 AM
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