gs.getSession.putProperty() in scoped application

Steve Kelly
Mega Sage

I'm trying to use gs.getSession().putProperty() in a scoped application widget on the service portal, but I am getting  an error that "Cannot find function putProperty in object com.glide.script.fencing.ScopedGlideSession@495843."

I know that gs.getSession() can be used in a scoped app, but does anyone know if the putProperty() method specifically cannot be used in a scoped app? I cannot find any documentation at all online. I confirmed the same functionality does work in the global scope.

4 REPLIES 4

Sri61
ServiceNow Employee
ServiceNow Employee

Hello Stevekellyau

gs.getSession.putProperty is not available within scoped application. Please refer to the scoped API reference for available APIs

In the below GlideSessionScopedAPI there is no scoped app equivalent.

https://developer.servicenow.com/dev.do#!/reference/api/madrid/server/c_GlideSessionScopedAPI

 

Thank you,

Sri

Hi Sri,

It is also not listed in the Global API documentation for GlideSession. So how am I supposed to know if and how it works in either?

Thanks,

Steve

This is an old post but I found it while researching a way to "stash" information for a session and thought I'd put in an update.

 

putProperty/getProperty are confirmed still working as of Xanadu.

However, it is an undocumented API, it may stop working at any time.

 

For this question, the following documented APIs seem to be the way going forward:

// server side
gs.getSession().putClientData("key", "value");
gs.getSession().getClientData("key");

// client side
// NOTE: you must establish the "key" on the server side as shown above before you can retrieve it on the client side.
// you cannot put the "key" on the client side. If you must put a value you can probably use AJAX to get to the server
// and do the put there.
g_user.getClientData("key");

Server : GlideSession - putClientData

Client : getClientData 

 

These work both server side and client side and are usable in scope.

I've tested them to "stash" key/value pairs in one business rule and retrieve them in another that's higher in order or further along the BR chain.

Onkar Pandav
Tera Guru

Hi,

  • gs.getSession().putProperty("result.status",status): Whether the user was successfully enrolled.
  • gs.getSession().putProperty("result.message",message): An associated message to be returned to the UI, such as a detailed error message.
  • gs.getSession().putProperty("result.value",value): A custom value associated with the enrollment.

Refer below link also.

https://www.servicenowguru.com/system-definition/working-with-system-properties/