Forum Discussion

JohannJ's avatar
JohannJ
New Contributor II
9 months ago

Extract detailed user info with business rule

Hi,

For user maintenance purposes we'd like to extract information like user email address etc, using business rules.

I've tried using BRApi.Security.Admin.* but that only seems to support extracting a few of the fields, like name, status and text fields.

If anyone has any ideas or suggestions on how to accomplish this, it'd be greatly appreciated if you'd share.

Have a good one,

Johann

  • JohannJ  - 

     

    BR

    Dim objGroupInfo As GroupInfo = BRApi.Security.Admin.GetGroup(si, secGroupName)

    Dim objUserInfo As UserInfo = BRApi.Security.Admin.GetUser(si, userName)


    SQL

    SELECT S.UniqueID as UserID , S.Name as Username, G.Name As GroupName
    FROM SECUSER S JOIN SECGROUPCHILD SG
    ON S.UniqueID = SG.CHILDKEY
    JOIN SECGROUP G
    ON SG.GROUPKEY = G.UniqueID

  • Krishna's avatar
    Krishna
    Valued Contributor

    JohannJ  - 

     

    BR

    Dim objGroupInfo As GroupInfo = BRApi.Security.Admin.GetGroup(si, secGroupName)

    Dim objUserInfo As UserInfo = BRApi.Security.Admin.GetUser(si, userName)


    SQL

    SELECT S.UniqueID as UserID , S.Name as Username, G.Name As GroupName
    FROM SECUSER S JOIN SECGROUPCHILD SG
    ON S.UniqueID = SG.CHILDKEY
    JOIN SECGROUP G
    ON SG.GROUPKEY = G.UniqueID

  • MarcusH's avatar
    MarcusH
    Contributor III

    You need to have a look at Methods. They are canned SQL statements that retrieve a load of really useful information. For the user email address you want to use the method Users:

    Using ds As DataSet = BRApi.Database.ExecuteMethodCommand(dbConnFW, XFCommandMethodTypeId.Users, "{}", "UserList", Nothing)
        If Not ds Is Nothing Then
            If ds.Tables.Count > 0 Then
                Dim dt As DataTable = ds.Tables("UserList").Copy
                For Each dr As DataRow In dt.Rows()
                    Dim UserName As String = dr("UserName")
                    Dim UserEmail As String = dr("Email")
                Next
            End If
        End If
    End Using

    That will give you the user name and their email address plus other data. To get more information on Methods and the data they provide, create a test Maintenance Unit and then create a Data Adapter, select Method as the Command Type. Method Type then populates a list of the available methods:

    Run that method and it shows the output with the column headers that you can then reference in a Business Rule.

     

    • sameburn's avatar
      sameburn
      Contributor II

      You can also extract name and email (and other properties) using this BRApi to retrieve the UserInfo object.

      Search GetUser in the BR snippets library

      ' Create stringbuilder		
      Dim sb As New Text.StringBuilder()		
      
      ' Get User
      Dim objUserInfo As UserInfo = BRApi.Security.Admin.GetUser(si, si.UserName)
      ' Get UserName
      sb.AppendLine(String.Format("UserName > {0}", objUserInfo.User.Name))
      'Get UserEmail
      sb.AppendLine(String.Format("UserEmail > {0}", objUserInfo.User.Email))
      
      ' Log Result -> Throw Error				
      Throw New XFException(Convert.ToString(sb))