LibraryEASYProcess Reference Manual 5ProcessesServicesHtmlWorkshopAddToSession

AddToSession Overview

AddToSession is used to add a session variable that you will want to reference later. This is useful if you want a certain value to be accessed after a few pages, but won’t be carrying that information forward via query strings.

Session variables are special variables that exist only while the user's session with your application is active. Session variables are specific to each visitor to your site. They are used to store user-specific information that needs to be accessed by multiple pages in a web application. Unlike a cookie, the information is not stored on the users computer.

The default behavior is to store the session variables in the memory space of the Internet Information Services (IIS) worker process. If you are using this default in-memory session management, the session variables will be cleared when worker process recycles. IIS Worker Process Recycling is the process whereby IIS kills off the child processes that it spawns to handle incoming requests and starts clean copies of them. Over time, problems could arise in the processing (memory leaks in the application code, undisposed resources, etc.) that IIS wants to clean up without having to shutdown the server. So it will periodically tell the worker process to die off, and spawn a new one.

The user’s IIS session ends when the worker process is killed. This happens on the session timeout (timeout set in IIS on application pool) or when closing the browser. After this point the session variables saved previously will be lost. If you need the variables to be around for longer than this, consider using cookies.

If you would like to override a session variable, this can be accomplished with another AddToSession service with the same variable name. The value will be replaced with the new session variable value.

AddToSession Use Examples
Overriding an Existing Variable
NameValuesThis is the container node that contains all the NameValue nodes. It does not accept any input, but you can Right-Click to add new NameValues (NameValue#0, NameValue#1, etc.). Each NameValue below this node is added to the session when this service runs.

NameValueThe NameValue is a container node which accepts no input, but represents a single session variable you are adding. Each NameValue node is indexed.

NameThis is the name of the variable you would like to add to the session. This will be used later to reference the variable. To retrieve the value, you must know the name you give it. This must be unique to the user and application. If you try to create a new variable with the same name, it will override the old one.

ValueThis the value you would like to assign to the variable.

AddToSession Use Examples

Basic AddToSession Use

In this example we have a button process which first tries to retrieve our TestVariable. If it is not found, it adds it.

The first time, we press the button, it tries to retrieve our session variable, which doesn’t exist yet and since it is not found, it is created in AddToSession.

Here are the inputs for that service and the logs of it running:

Now it is a session variable that exist and the next time we click the button, the RetrieveFromSession service will find the value and output it to the user is a message.

Now if we close the browser and try again, it again will not be found. The same will happen if we let the page sit long enough to reach the session timeout. Usually users see this as leaving the page open for a long time and when they return, they are required to log in again. This is because we keep track of the logged in user by their session variables.

Using AddToSession to Store CartId

In this example, the GetCartId process has been called and the output should return a default cart id for the user.

We query the database to look for a default cart for the user. If the user just placed an order, their cart would be deleted and a default cart would not be found. From there, the process will create a new default cart for the user if one was not found.

At this point, the user has a default cart and the process adds that cartid variable to the session. This way, it can easily be retrieved by a RetrieveFromSession service. After this, the process also outputs the CartId so that wherever the GetCartId process is called, the output returns the cart id.

Here is a closer look at those AddToSession service inputs:

Here is one of the places that uses the session variable we just saved. When the tax amount is needed the GetTax process is called.

  1. It first checks if tax should be hidden for the site.
  2. Then it checks if this particular user should have tax hidden.
  3. After that, it checks if we are finding the tax for the cart or for an already placed order in JDE.
  4. If the tax needs to be calculated for the cart, it then checks if the CartTotal was passed in through the input. If not, it will need to be calculated.
  5. If we are going to calculate the CartTotal, we will need the CartId. Retrieve CartId with RetrieveFromSession service.

Here is a closer look at the service’s inputs:

Overriding an Existing Variable

RemoveFromSession is an available service, but it not often used because you do not need to first remove the old variable in order to add a new one. AddToSession can be used to override the existing value with a new one.

In this example, we have a button process which sets a variable, then overrides it. We will then retrieve the value and display the value to the user in a message.


Here is the message that displays after the button is clicked and runs that process:

Here in the logs we can see that both AddToSession services were successful, so the last run AddToSession service is the last time the variable was edited, leaving it at that value.

Powered by EASYProcess (© 2022 K-Rise Systems, Inc).