Thursday, 17 August 2017

In Memory Session State - Simple Example

Not too long ago I encountered an interesting behaviour with session state, turns out not long after Dick Dral posted a very similar article that I had not yet seen.

Recently I encountered an even easier scenario.

I had a bunch of columns where I wanted to use the same prefix across all headers, but I wanted to define the value once, referring to it many times. I'm betting on the fact someone may change their mind.

Interactive Report with pivoted data

So I created a hidden item called P222_PREFIX and gave it a static source of "Ch".

Page item source

If I substitute this item as part of the column heading for each column, it will use the value found session state - not the database value, but the value based on the defined source, placed only in memory for the duration of page rendering.

Column heading

So while the output may appear as desired after the page renders, if the region is partially refreshed by hitting "Go" on an interactive report or just triggering region refresh, the prefix will disappear because there is no value for P222_PREFIX in session state once the page finishes rendering.

Desired output

To fix the problem we add a computation on the hidden item to set the value, instead of using a static source. This ensures the value is in session state for current and later usage.

An alternative solution to the task at hand might be to use Shortcuts.

4 comments:

Anonymous said...

There will (probably - you know, safe harbour, ...) be a new feature in 5.2 that you can use for static substitions. We will support that for text messages. You can define a text message, e.g. P222_PREFIX, then use it with substitution syntax like this: &APP_TEXT$P222_PREFIX.

The advantages are that there won't be I/O for session state and that you automatically get translation support for multi lang apps.

Scott Wesley said...

I think I understand what you're saying, sounds like an interesting idea.

I'm all for better performance, especially with something as simple as skipping session state I/O.

semsem said...

Is in-memory session state values are only kept until the page is fully rendered or until the page is closed? I am on 18.2. and created an item(:T1) with a static source=4 and a button with an alert dynamic action that has a server-side condition of item(:T1) is not null. And when I clicked the button, the alert displayed which means the in-memory value is still there. Is that right or Am I missing something or the behavior changed in 18.2?

Scott Wesley said...

Sounds like it could be. Your best bet would be build a test case and demonstrate on APEX forum.