Glide session concept/api with some example of getClientData() and putClientData()

jim38
Mega Contributor

Hello Experts can you help me out on Glide session concept/api with some example of getClientData() and putClientData()?

1 ACCEPTED SOLUTION

Ganesh Pardhe
Kilo Guru

Hello Jim,

 

In addition to Kunal I want to add more points like

The GlideSession class has no constructor, but it is returned from the getSession() method of the GlideSystem API (gs.getSession();).

This API allows you to get and set data related to the current session.

 

Example usage

In business rule on the Incident table, we can place some data in the user's client session like so:

var userSession = gs.getSession();
session.putClientData('ticket_number', current.getValue('number'));

And then in a client script, you can access this data like so:

var ticketNumber = g_user.getClientData('ticket_number');

 

PFB Link for more reference for Can I write to a session variable from within a scoped app?

https://community.servicenow.com/community?id=community_question&sys_id=1df9cb29db5cdbc01dcaf3231f96...

 

If my answer is worth to you,Please mark correct and helpful.

regards,

Ganesh

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please check below links:

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideSessionSc...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for the response.

Kunal Varkhede
Tera Guru

Hi,

 

The getClientData() and putClientData() methods allow you to set data in the user's session from a server-side script using putClientData(), and then retrieve that data using getClientData().

This functionality can be extremely useful for passing data back-and-forth between the server and client, without performance-costly synchronous queries or time-consuming Ajax calls.

Refer @Ankur Bawiskar provided link also as well as below docs

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/client_scripts/reference/r...

 

Thanks,

Kunal

Ganesh Pardhe
Kilo Guru

Hello Jim,

 

In addition to Kunal I want to add more points like

The GlideSession class has no constructor, but it is returned from the getSession() method of the GlideSystem API (gs.getSession();).

This API allows you to get and set data related to the current session.

 

Example usage

In business rule on the Incident table, we can place some data in the user's client session like so:

var userSession = gs.getSession();
session.putClientData('ticket_number', current.getValue('number'));

And then in a client script, you can access this data like so:

var ticketNumber = g_user.getClientData('ticket_number');

 

PFB Link for more reference for Can I write to a session variable from within a scoped app?

https://community.servicenow.com/community?id=community_question&sys_id=1df9cb29db5cdbc01dcaf3231f96...

 

If my answer is worth to you,Please mark correct and helpful.

regards,

Ganesh