215
Views
5
Comments
Solved
Use session variable when consuming api
Question

Hey guys,

I am building an application in which I consume a REST API. One of the requirements is to store the original request-url and corresponding response message, in combination with an requestID provided by the producer of the RESTAPI in the response body. The way I solve this is the following:

  1. In an OnBeforeRequest I store the request-url as session variable
  2. In an InAfterResponse I store the request-url (from the session variable) and the response message in an entity, subsequently the ID of the record is stored as a session variable
  3. In the Server Action that calls the consumed API the requestID added to the Entity record with same ID (as stored in the session variable)

The solution seems to work when I debug, but I wonder if it still works if more Server Actions a initiated at the same time. Can someone confirm that the Session Variable value won't be affected by another (instance) of the Server Action?

Thanks!

- Funs

2025-08-22 10-19-44
Pramod Jain
 
MVP
Solution

Hi Funs,

Thanks for the clarification, two things here .

1.  Since timer run asynchronous on a separate session thus if you are using Session variable in your timer they will be limited to that timer session itself and wont impact any user session.

2. No matter how many server action you initiated OS won't change your session data until any of your action does not have the code to update the session variable.


Regards,

-PJ-

2025-08-22 10-19-44
Pramod Jain
 
MVP

Hi Funs,

The lifespan of the session variable is throughout the user login session and thus if you perform other server action within the same login session it wont impact the existing session variable.

If you are updating the same session variable in other action the value will be changed and you will get the most recent value in it.

Please let me know if i understand your question correctly or not ?


Regards,

-PJ-

2024-04-26 09-08-41
Funs Vercoulen

Hi Pramod,

Thanks for your reply. Something important I forgot to mention is that it is a server action that will be initiated by a timer, so there will be no direct user interaction.

Also I don't update the same session variable knowingly, but I guess my question is if OutSystems will do that when more server actions are initiated at the same time, or are they sequentially?


Kind regards,

- Funs

2025-08-22 10-19-44
Pramod Jain
 
MVP
Solution

Hi Funs,

Thanks for the clarification, two things here .

1.  Since timer run asynchronous on a separate session thus if you are using Session variable in your timer they will be limited to that timer session itself and wont impact any user session.

2. No matter how many server action you initiated OS won't change your session data until any of your action does not have the code to update the session variable.


Regards,

-PJ-

2024-04-26 09-08-41
Funs Vercoulen

Thanks Pramod, I guess the solution will also work for timers and more server action instances

UserImage.jpg
Mani S

My question is a bit different. 

During the OnBeforeRequest, i want to examine a session variable, store its value and InAfterResponse i want to reset the same session variable.

Will it work as exptected?

These actions are at server side, right?

onBeforeRequest :  Session.get("SessionLoginTime")  say --> 18-Dec-2021 11:00:00

at 11:15, i make a AJAX call to a server URL and i do not want that request to extend my session time out value. The user is not doing any action on the web page. this ajax call happens every 15 mins.. If, the user does not do any action on the web page, the page should timeout by 11:20 (session timeout)

onAfterResponse : Session.set("SessionLoginTime, "18-Dec-2021 11:00:00")  <-- set the previous value...

Essentially, this request is a AJAX call to the server from the browser, i do not want the session get extended..

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.