Skip to main content
1-Visitor
June 27, 2019
Solved

Failing to persist session data on reload or navigation from one mashup to another

  • June 27, 2019
  • 10 replies
  • 5714 views

Scenario:

User sets a value that needs to be persisted for the session until the user logs out or sets a new value himself.

 

What's done so far

 

1. Created thingshape > added it to the user subsystem > property in the ThingShape is persistent

2. On the mashup there's a text box to accept value from the user > set button which calls the setter service with following code :

 Resources["CurrentSessionInfo"].SetGlobalSessionStringValue({
	name: "unitNumber" /* STRING */,
	value: unitNumber /* STRING */
});

3. There's a label widget on the mashup to show the value set by the user, which calls the Resources["CurrentSessionInfo"].GetGlobalSessionValues which returns a persistent property value unitNumber, set above by the setter service.

4. ServiceInvokeCompleted event from the setter service is bound to the Getter to return this value.

5. This works fine

 

Problem:

Once the mashup is refreshed or user navigates from current mashup to another and comes back, the session value for unitNumber set by the user disappears.

 

Not sure if I am missing any further step to persist this. Could someone please help point my mistake here

 

Thanks!

 

EDIT:

TWX version : 8.4.2

Best answer by bootstrap

Ok I think i found the issue, it is about setting textBox widget value directly with the session parameter. This should not be done, (also noted in that article I added in my previous response)

 

To make it persistent value need to run through the setter service and not via the Session parameter in the mashup.

10 replies

19-Tanzanite
June 28, 2019

Hi,

 

If the getter only executes on service invoke completed of the setter, you will not be able to see the session value on a new page load.

Bind as a trigger to the getter the mashup loaded as well - or bind the session variable directly.

If you're interested, in developer tools you can also use TW.Runtime.Session.GetSessionValue("MyKey") to see what value is stored on the client side - use it only to check, but not in production code, as it's not guaranteed not to change in future. 

 

bootstrap1-VisitorAuthor
1-Visitor
June 28, 2019

Thanks! @VladimirRosu_116627 

 

I missed to add this info but i do i have bind on getter when page reloads so basically the getter is also executed them page is refreshed or when user navigates back to this mashup.

 

This I wasn't aware, but just wondering how does TW.Runtime.Session.GetSessionValue("MyKey")  differ from the Resource > GetGlobalSessionValues?

 

I did test with binding the session variable directly to the label widget.

 

19-Tanzanite
June 28, 2019

One is executed server side, the resource approach, and the TW.Runtime is executed locally in the browser, internally, by the Mashup runtime.

I would use the javascript code in the console to check if internally the Mashup Runtime has the value you have set.

Ideally the results of both methods should be in sync.

The Session Variables themselves exist across the browser and the server at the same time.

Can you somehow attach the example mashup here?