HowTo: GAM User table extensibility: multivalued attributes

Official Content

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

Here we see how to add multivalued attributes to the GAM User table.

Add multivalued attributes to GAM User Table

An example is if you want 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.

GAMUserAttributeObject
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
Figure #2

Example code:

&GAMUser.Load(&UserGUIDselected)
&UserAttr      = new ()  //&UserAttr is GAMUserAttribute data type
&UserAttr.Id     = &UserAttrMultiValueId //&UserAttrMultiValueId is GAMPropertyId data type
&UserAttr.IsMultiValue   = True
&UserAttr.Value    = &UserAttrMultiValueId

&UserAttrMultivalue     = new () //&UserAttrMultivalue is GAMUserAttributeMultivalues
&UserAttrMultivalue.Id  = &AttrValueToAdd1 //&AttrValueToAdd1 is GAMPropertyId data type
&UserAttrMultivalue.Value  = &AttrValue1 //&AttrValue1 is GAMPropertyValue data type
&UserAttr.MultiValues.Add(&UserAttrMultivalue)

&UserAttrMultivalue     = new ()
&UserAttrMultivalue.Id  = &AttrValueToAdd2
&UserAttrMultivalue.Value  = &AttrValue2
&UserAttr.MultiValues.Add(&UserAttrMultivalue)

&GAMUser.Attributes.Add(&userattr)

&GAMUser.Save()
If &GAMUser.Fail()
  For &Error In &GAMUser.GetErrors() //&Error is GAMError data type
   msg(&Error.Message + !"(GAM" + &Error.Code.ToString().Trim() + !")")
  EndFor
Else
  Commit
EndIf

GET, Update or delete multivalued attributes      

These methods are available as 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)

Examples

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


&GAMUser.Load(&UserGUIDselected)
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
   endfor
  endif
EndFor

Delete a GAMUserAttributeMultivalues object

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

Update a GAMUserAttributeMultivalues object

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

See Also

HowTo: Extend GAM entity properties