How to restart user session from AL language

Hello reader, in this post I would like to illustrate a way to automate the page update process (user session) within your AL application.

Sometimes, it happens that there are operations that, to take effect, the user session must be able to be restarted. For example, in Business Central we have an example when the company badge is changed from the company information page. When the page is closed, a confirmation message will ask us if we want to restart the session or not. This usually happens if we need to make graphical changes to the client or pages.

But if we wanted to implement the update in our own application, how could we do it?

We can use the complex variable SessionSettings to restart the session. SessionSettings, as mentioned, is a complex object that accesses the user’s information stored in the User Personalization table. For more information, you can consult the guide.

Let’s see with an example how to use it. Imagine adding an action to the article card called ‘Update page’ that performs the restart of the user session. Let’s see in the following example the code to do it.

As you can see, through the RequestSessionUpdate function, we force the update of the user session.

Use RequestSessionUpdate to restart the user session of the client, but remember that:

  1. it is not a function that replaces SELECTLATESTVERSION which takes care of deleting all the unlocked records from the client’s cache, thus ensuring the reading of the most recent data. The method also clears the current client session cache for CaptionClassTranslate strings. The strings will then be re-evaluated by the CaptionClassTranslate method trigger in codeunit 42.
  2. Do not run any other AL code after calling RequestSessionUpdate because, by updating the user session, the previous values will be lost.

I hope this post has given you more knowledge for the development of your next apps in Microsoft Business Central.

Leave a Reply