RetrieveFromSession Use Examples
Basic Use Example
In this example we have a button process which first tries to retrieve our TestVariable. If it is not found, it adds it.
Here is a closer look at the input used in RetrieveFromSession:
When the page loaded, we clicked the button, and the logs showed this variable did not exist, so it returned blank.
Notice the service didn’t throw an exception, it returned the requested variable, but since it did not exist, the value was blank.
Since we set up our process to create the variable if it wasn’t found, the next time we click the button it should be found
We also set up our process to show a message on the webpage when the variable exists:
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 RetrieveFromSession to Find CartId
In this example, the shopping cart id is saved as a session variable when the user logs in and every time they need a new cart. This way, anywhere on the site, when a new cart is requested, developers only need the RetrieveFromSession service.
When Calculating Tax in Cart
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.
- It first checks if tax should be hidden for the site.
- Then it checks if this particular user should have tax hidden.
- After that, it checks if we are finding the tax for the cart or for an already placed order in JDE.
- 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.
- 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:
In the Cart Overview Section and the Site Header
These sections give a summary of the items in your cart and the order you are able to place. One of the things they provide is the current cart subtotal. Here is the process that sets those values:
The first thing it does it Retrieve the cart id with RetrieveFromSession. With that it calculates the subtotal for the cart. Depending on whether there are any items in the cart it takes different action. For the site header that means displaying either “Cart” or “Cart ($[Subtotal])”.
When Reordering an Order From Order History
There is a Reorder process that is called from a couple of places. Each place that has a Reorder button calls this process.
The process starts by retrieving the current cart id from the session. It needs to do this because sometimes reorder should clear your existing cart. It might have to do this if the order you are trying to reorder has a different branch plant then your current cart and the site you are on limits your shopping cart to one branch plant. In this case, we can’t just clear your cart, because it might be an important cart.
There is another feature called saved carts, which allows you to save your cart and give it a nickname. When your current cart is saved as has a nickname, instead of clearing it, we should just set it aside for you to come back to later.
After retrieving your cart id, it then queries JDE for the order you want to reorder. At this point it does the comparison to see if they have different branch plants and whether or not they can be combined.
If your current cart does need to be cleared, it then checks if your current cart is saved. If it is, it will need to be set aside, while the user is assigned a new default cart. The order from JDE will then be duplicated in that default cart.