Table of contents

Official Content

GeneXus Access Manager (GAM) User entity can be extended using the methodology explained in Extensibility of GAM entity properties, based on OAV pattern.

This article shows you the steps to add multivalued attributes to the GAM User table.

Add multivalued attributes to GAM User Table

Suppose you need to store the telephone numbers of a user (home, job, mobile phone, etc). You need to define a variable based on GAMUserAttribute data type, where you should store the "Id" and "value" of the attribute you are defining. In the example, both Id and value could be "Telephone number".
The "isMultivalue" property should be set to True.

GAMUserAttribute exeternal object v18u4
Figure #1

The "Multivalues" property is of GAMUserAttributeMultivalues collection data type, and it stores a vector with the "Id" and "value", in the example it could be ("job number", "235555"), ("home number",97666), etc.

GAMUserAttributeMultivalues v18u4
Figure #2

Sample code:

    &GAMUser = new()
    &GAMUser.Name                   = !"Nickname"
    &GAMUser.EMail                  = !""
    &GAMUser.FirstName              = !"Juan"
    &GAMUser.LastName               = !"Perez"
    &GAMUser.Password               = !"123"
    &GAMUser.Phone                  = "2601 20 82"
    &GAMUser.URLProfile             = !",Toc%3AGeneXus+Access+Manager+%28GAM%29"
    &GAMUser.DontReceiveInformation = False
    &GAMUser.CannotChangePassword   = False
    &GAMUser.MustChangePassword     = False
    &GAMUser.IsBlocked              = False
    &GAMUser.PasswordNeverExpires   = False
    //User Attributes (optional)
    &GAMUserAtt              = new()
    &GAMUserAtt.Id           = !"EmployeeID"
    &GAMUserAtt.IsMultiValue = False
    &GAMUserAtt.Value        = !"123456"
    &GAMUserAtt              = new()
    &GAMUserAtt.Id           = !"Company"
    &GAMUserAtt.IsMultiValue = True
    &GAMUserAttMV            = new()
    &GAMUserAttMV.Id         = !"GX"
    &GAMUserAttMV.Value      = !"GeneXus"
    &GAMUserAttMV            = new()
    &GAMUserAttMV.Id         = !"GL"
    &GAMUserAttMV.Value      = !"Globant"
    If &GAMUser.Success()
        &GAMErrorCollection = &GAMUser.GetErrors()
        For &Error in &GAMErrorCollection
            Msg(Format(!"Save User %1 error: %2 (GAM%3)", &Name, &Error.Message, &Error.Code))

GET, Update or delete multivalued attributes      

These methods are available since GeneXus X Evolution 3.                                                         

Method Description
&GAMUser.GetMultiValuedAttribute(in:&GAMPropertyId, in:&GAMPropertyId, out:&GAMError collection): GAMPropertyValue Given the GAMUserAttribute.Id for a multivalued GAMUserAttribute, and the GAMUserAttribute.Multivalues.Id, it returns the Value corresponding to that pair (see figure #1 and figure #2)
&GAMUser.SetMultiValuedAttribute(in:&GAMPropertyId, in:&GAMPropertyId, in:&GAMPropertyValue, out:&GAMError collection):Boolean

Given the GAMUserAttribute.Id for a multivalued GAMUserAttribute, and the GAMUserAttribute.Multivalues.Id, it updates the Value of this object with the given GAMPropertyValue parameter (see figure #1 and figure #2 for a reference).

&User.DeleteMultiValuedAttribute(in:&GAMPropertyId, in:&GAMPropertyId, out:&GAMError collection): Boolean Given the GAMUserAttribute.Id for a multivalued GAMUserAttribute, and the GAMUserAttribute.Multivalues.Id, it removes the record corresponding to that pair (see figure #1 and figure #2)


Get the GAMProperty value of all of the multivalued GAMUserAttribute objects of a GAM user

For &UserAttr In &GAMUser.Attributes //&UserAttr is GAMUserAttribute data type
  &UserAttributeId = &UserAttr.Id
  &AttrValue = &UserAttr.Value
  if &UserAttr.IsMultiValue

   &GAMUserAttrMultiValuesCollection = &UserAttr.MultiValues //&GAMUserAttrMultiValuesCollection is collection of GAMUserAttributesMultivalues data type
   for &GAMUserAttributeMultivalues in &GAMUserAttrMultiValuesCollection
    &GAMPropertyId = &GAMUserAttributeMultivalues.Id
    &GAMPropertyValue = &GAMUser.GetMultivaluedAttribute(&UserAttributeId,&GAMUserAttributeMultivalues.Id,&errors) //&errors is collection of GAMError

Delete a GAMUserAttributeMultivalues object

&isok = &GAMUser.DeleteMultivaluedAttribute(&UserAttributeId,&GAMPropertyId,&errors)
if &isok
  For &Error In &errors
   msg(&Error.Message + !"(GAM" + &Error.Code.ToString().Trim() + !")")

Update a GAMUserAttributeMultivalues object

&isok = &GAMUser.SetMultivaluedAttribute(&UserAttributeId,&GAMPropertyId,&GAMPropertyValue,&errors)
if &isok
  For &Error In &errors
   msg(&Error.Message + !"(GAM" + &Error.Code.ToString().Trim() + !")")

See Also

HowTo: Extend GAM entity properties

Last update: April 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant