GlideSession: When to use get/setProperty versus get/putClientData

Jim Kerrigan
Kilo Expert

When would I select gs.getSession.getProperty and .putProperty versus gs.getSession().getClientData and .setClientData?

 

Is there a relationship between the getSession property methods and instance properties?

6 REPLIES 6

sachin_namjoshi
Kilo Patron
Kilo Patron

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.

 

You can get the Browser details from a user sessions like below

 

 

gs.getSession().getProperty('user_agent_browser'); // For browser

gs.getSession().getProperty('user_agent_version'); // for browser version

 

Regards,

Sachin

Jim Kerrigan
Kilo Expert

Sachin

Thank you.

What default properties are set beyond browser name and version?

If I put my own name in the property, I can put and get those values.

Jim

Jim Kerrigan
Kilo Expert

In effect, why use property versus client data?

// ---------------- ----------- -------------------------------------- -----------
// Jim Kerrigan     03-Sep-2020 Initial coding                         STRY0012345
// ---------------- ----------- -------------------------------------- -----------
//
// Query about GlideSession.
//
// Set some constants.
   propertyName    = 'custName' + 'Property';
   propertyValue   = 'Harry'    + 'Property';
   clientDataName  = 'custName' + 'ClientData';
   clientDataValue = 'Harry'    + 'ClientData';
//
// Retrieve the session object.
   var session = gs.getSession();
//
// Set the values.
   session.putProperty   ( propertyName,   propertyValue   );
   session.putClientData ( clientDataName, clientDataValue );
//
// Show the values.
   gs.info ( propertyName   + ' propertyValue value should be '   + propertyValue   + ': ' + session.getProperty   ( propertyName   ) );
   gs.info ( clientDataName + ' clientDataValue value should be ' + clientDataValue   + ': ' + session.getClientData ( clientDataName ) );
//
// That's all.

*** Script: custNameProperty propertyValue value should be HarryProperty: HarryProperty
*** Script: custNameClientData clientDataValue value should be HarryClientData: HarryClientData

 

 

ArminB
Tera Contributor

Session has properties on it, put there by processes prior to and during/after login. Where are those properties documented?