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.

2 comments:

chrisonoracle 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.