Can I write to a session variable from within a scoped app?

brianrichards
Tera Guru

Here is my problem:

I have created a custom table within a scoped app, and I have added a UI action to show a link on the form for this table in order to launch a specific record producer. In the UI action I have the following script:

var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=683d4adf0f4c43006a4a419ce1050e91';  

gs.getSession().putClientData('room',current.sys_id);

action.setRedirectURL(url);  

This UI Action fails to execute (drops me back to the list view without redirecting.)

If I create this exact same UI Action in global against a global table, it executes fine and the session variable 'room' is available for me to 'getClientData()' from the record producer.

From this I have guessed that I cannot putClientData() from within a scoped app.

First of all, WTH. Secondly, is there an alternative that would allow me to pass a value from a UI action to a record producer so I can do something nice and simple like populate a record producer field?

Thanks for the help!

Brian

1 ACCEPTED SOLUTION

Gosia Urbanska
Giga Guru

Hi Brian, Did you solve your issue? In a case that someone would need a solution; I've just finished an   implementation for scoped application using sessions;



My goal was to pass current sys_id to "scripted filter" used in report



My solution:



1) UI Action :


var session = gs.getSession();


session.putClientData('sysID', current.sys_id.toString()); //!!!! IMPORTANT need to pass string


var published_url = '/sys_report_display.do?sysparm_report_id=8c4e773adb300300e1dc72ffbf961949';


action.setRedirectURL(published_url);



my script include:


client callable: true


name: getCurrentEvent


Script:


function getCurrentEvent(){


var session = gs.getSession();


var event = session.getClientData('sysID');


//session.clearClientData('sysID');


return event;


}


or to get session values in client side:



create client script onLoad and call var v = g_user.getClientData('sysID');


View solution in original post

5 REPLIES 5

Hi Brian,

Any idea how to get getClientData in server side?

My requirement is mentioned in https://community.servicenow.com/community?id=community_question&sys_id=4b83a5dedb64a010fb4ae15b8a9619c1 post