(web P10) Session variable values changed on popup lost after popup notify action

(web P10) Session variable values changed on popup lost after popup notify action

  

Hi all,

i'm struggling with this issue, i'm using a session variable that is a structure containing several attributes. 

1. I have a screen that contains a button that calls a popup widget (the screen uses https protocol)

2. On the popup i've an action that assigns new values to the session variable attributes 

(before close the popup using the popup notify and popup close actions, i see the session variable values updated)

3. After closing the popup, when the OnNotify action on the screen runs, the session variables are not updated (even before i saw all the Session variable values being updated on the popup)

I checked if this is being caused by the use of https / http protocols, but apparently both screen and popup are using https, so they must share the same session right?

Anyone have a clue why this is happening?

Thanks

Best regards




Hi Severiano,

just (maybe) a silly question...are you using those session variables on the OnNotify action? On an assign or in any logic?

Cheers

Hi Severiano,

Some more question... Are you seeing that issue in the debugger? Or is the value (of the session variable) in the screen?

If it is on the debugger, the debugger only shows the values that are used.

Cheers,

José

Gonçalo Azambujo wrote:

Hi Severiano,

just (maybe) a silly question...are you using those session variables on the OnNotify action? On an assign or in any logic?

Cheers

Hi Gonçalo,

yes i'm currently using this session variable on the parent page and also on other screens, not on the OnNotify action indeed. Can i ask why? does it matter?

thanks for the feedback


José Costa wrote:

Hi Severiano,

Some more question... Are you seeing that issue in the debugger? Or is the value (of the session variable) in the screen?

If it is on the debugger, the debugger only shows the values that are used.

Cheers,

José

Hi José,

i see this happening using the debugger, 

on the popup action after assigning new values to the Session Var i see the values being updated. Then on the OnNotify action of the screen, i'm also checking the same Session Var through the debug and is not updated.

this is the action on the popup, as you can see the session var is updated after the assign


after this the popup_editor_notify runs, and calls the OnNotify action on the screen, as you can see the session var isn't updated 


As far as i know this can only happen if the screen and the popup are not sharing the same session. Is this possible? Do you have any idea? 

really thanks for the feedback


Hi Severiano,

And are you using those values someplace else? Try to add a XY Expression in the inside of the container that is refreshed. Or create a dummy entity with just one or two attributes and do a Create with the values from the session. To see if the values are there or not.

As I said, in the debugger you only see the values if they are used somewhere. Otherwise, the debugger will show the default values.

Cheers,

José

Solution

Hi Severiano,

My experience with Session variables comes from platform version 9.1, but I think they didn't changed to 10. 

Session variables are loaded from database on every request, and any changes to them will be stored only at the end of the request (automatically).

But by "request" here we are not talking only about the requests made by the browser to the server. You can put in this category also calling server actions or doing notifies (afaik).

Let's see an example:

User press a button in screen that calls the screen action A. Before executing this screen action, all session variables are loaded from database. We have only one: Number, whose actual value is 1.
You than use an assignment to change its value to 2. After it, you call a Server Action B.

Before executing the Server Action B, the session variables will be loaded from database, so, inside Server Action B, Number has the value 1.
When Action B ends and the flow returns to Action A, the value of the Session Variable is 2. At the end of this action, this value will be stored. 

It seems that this happens because each Action has its own "copy" of the session variables.

The solution is to pass arguments instead of using Session Variables. Like, as you are notifying the parent, pass the information you want in the notification message, instead of relying on Session Variables.

(As soon as I get to a Service Studio, I'll test this in platform 10).

Cheers.
Eduardo Jauch  

EDIT

Also, using session variables with types different than Basic types or entity identifiers is bad practice. It will degrade your platforms performance. You may not "feel" it in development, but when your application starts to be used by more users at the same time, this will happen...

Solution

Hi Eduardo, 

you're absolutly right on both points, about using Session variables to pass parameters between screen and popup and also the fact i'm using a complex structure as Session var instead of a basic type. Somehow the issue i was struggling is related with both.

Firstly the reason why i wasn't using the notification message to pass parameters, is because i intended to pass several fields an not only one, to avoid calling a rest API twice.

After some debuging i notice that only the values of Session vars defined as basic types where being passed from the popup action to the OnNotify action on the screen, and never using a complex structure such as mine. 

One the other hand i also notice that,  if i dont call the OnNotify action from the popup, calling just the popup_close action, and then refresh the page (f5) the Session vars values (even complex struct) updated on the popup persists. 

Based on this i was pointing to something related with the viewstate, or something that happens on the OnNotify logic that i wasn't aware. 


I couldn't perfectly understand why my approach didn't work using the complex structure. But the solution was, indeed use the best practices suggested by you, about using the notification message to pass the parameter and then on the screen get the data from  the API and assign to the session var.

If you want to check this issue, i could try to create a sample OML.


Thanks

Best regards



José Costa wrote:

Hi Severiano,

And are you using those values someplace else? Try to add a XY Expression in the inside of the container that is refreshed. Or create a dummy entity with just one or two attributes and do a Create with the values from the session. To see if the values are there or not.

As I said, in the debugger you only see the values if they are used somewhere. Otherwise, the debugger will show the default values.

Cheers,

José

Hi José,

your help has been also useful

thanks for the feedback

Severiano Melo wrote:

Firstly the reason why i wasn't using the notification message to pass parameters, is because i intended to pass several fields an not only one, to avoid calling a rest API twice.

You can pass multiple information in the message of the Popup_editor_Notify. Just concatenate the information using a separator, like: info1 + "|" + info2 + "|" + infon

In the OnNotify, you get the message, use the StringSplit action from the Text extension to return a list based on the separator and use the information accordingly.

After some debuging i notice that only the values of Session vars defined as basic types where being passed from the popup action to the OnNotify action on the screen, and never using a complex structure such as mine. 

One the other hand i also notice that,  if i dont call the OnNotify action from the popup, calling just the popup_close action, and then refresh the page (f5) the Session vars values (even complex struct) updated on the popup persists. 

This happens because when you do the F5 (refresh), the new values of the session will be already stored in the database and when the page is remade, they will be used.

Based on this i was pointing to something related with the viewstate, or something that happens on the OnNotify logic that i wasn't aware. 

The Session variables are stored in database, not in the viewstate (like local screen variables).

I couldn't perfectly understand why my approach didn't work using the complex structure. But the solution was, indeed use the best practices suggested by you, about using the notification message to pass the parameter and then on the screen get the data from  the API and assign to the session var.

If you want to check this issue, i could try to create a sample OML.

I'll do a test (when possible) to check in the case of the NOTIFY specifically, what was happening, but I don't expect it to work no matter if the session variable is of type basic or compound/structure...

In any case, if you solved the problem, please, mark the correct answer, so that others can benefit from it :)

Cheers.
Eduardo Jauch

Hi Eduardo,

sure i mark your early answer as the solution.

Really thanks for all the feedback

Best regards