Initializing session context after login

When using the GAM Integration Module, every time a user logs in a procedure named UpdateContextAfterLogin is called.

This procedure can be used by the developer to initialize user context and retrieve user-specific configuration and load it into the session.

This can be useful to solve these scenarios:

  1. Loading Design System options into the session.
  2. Loading user information into the K2BContext object for later use.

This procedure will not be overwritten by K2BTools when upgrading from most versions to newer versions. The only scenario where this object may be updated would be if a breaking change requires an update in the procedure parameters.

Example 1 - Loading Design System options into the session

To load design system options into the session, you can use code similar to the one below.

&GAMUser = GAMUser.Get()
&GAMUserAttribute = &GAMUser.GetAttribute(DesignSystemOptions.BaseColor, &Errors)
If &Errors.Count = 0
    K2BSessionSet(DesignSystemOptions.BaseColor, &GAMUserAttribute.Value)
EndIf

This code is based on the fact that the K2BTools.GetDesignSystemOptions object loads the default value for the design system options from the session as loaded in this code.

In this code, the base color is loaded from a user attribute. To persist the value in that location add this code to the SetDesignSystemOptionValue procedure:

&GAMUser = GAMUser.Get()
&GAMUserAttribute = &Session.User.GetAttribute(&OptionName, &Errors)
If &Errors.Count = 0
    &GAMUserAttribute.Value = &OptionValue
    &Session.User.SetAttribute(&GAMUserAttribute, &Errors)
Else
    &GAMUserAttribute = new()
    &GAMUserAttribute.Id = &OptionName
    &GAMUserAttribute.Value = &OptionValue
    &GAMUserAttribute.IsMultiValue = false
    &GAMUser.SetAttribute(&GAMUserAttribute, &Errors)    
EndIf

&GAMUser.Save()
commit

Example 2 - Loading values into the K2BContext variable

You can use code similar to the following to load values into the context:

&Session = GAMSession.Get(&Errors)
K2BGetContext.Call(&Context)
&Context.UserCode = &Session.User.Name
K2BSetContext.Call(&Context)