Forum Discussion

DK_OS's avatar
DK_OS
New Contributor
28 days ago

What IMPORT should i use for the SECURITY updates for BRApi

Hi All,

i am new to OneStream, i tried creating BR for Security automation. below is my entire code in OS-BR.

Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.Common
Imports System.Globalization
Imports System.IO
Imports System.Linq
Imports Microsoft.VisualBasic
Imports OneStream.Finance.Database
Imports OneStream.Finance.Engine
Imports OneStream.Shared.Common
Imports OneStream.Shared.Database
Imports OneStream.Shared.Engine
Imports OneStream.Shared.Wcf
Imports OneStream.Stage.Database
Imports OneStream.Stage.Engine

Namespace OneStream.BusinessRule.Finance.BR_UserManagement
    Public Class SecurityGroupHelper

        Public Sub ShowQAGroups(ByVal si As SessionInfo, ByVal api As FinanceRulesApi)
            Try
                ' Get all security groups using the API passed to the function
                Dim allGroups As GroupInfo = BRApi.Security.Admin.GetGroup(si, "QA_Admin")

                ' Loop through all groups and display a MessageBox for each that starts with "QA_"
                For Each grp As MemberInfo In allGroups
                    If grp.Member.Name.StartsWith("QA_") Then
                        MessageBox.Show(grp.Member.Name, "QA Group Found")
                    End If
                Next

            Catch ex As Exception
                Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
            End Try
        End Sub

    End Class
End Namespace

---------------------------------------------------------------------------------------

I am getting error as below. i am not sure what mistake in the code. one i am sure about messagebox.show.

Error compiling Business Rule 'BR_UserManagement'. 

1) Error at line 27:  Expression is of type 'GroupInfo', which is not a collection type. 

2) Error at line 29:  'MessageBox' is not declared. It may be inaccessible due to its protection level.

5 Replies

  • MarcusH's avatar
    MarcusH
    Valued Contributor

    You have requested a single security group:

    Dim allGroups As GroupInfo = BRApi.Security.Admin.GetGroup(si, "QA_Admin")

    So the error is saying that you are treating the return allGroups as a collection ie you think it contains List(Of GroupInfo) when it is a single GroupInfo. Get rid of the For loop. And as sameburn​ says MessageBox is not valid - use api.LogMessage for Finance BRs. And you then will be checking the name like this:

     If allGroups.Member.Name.StartsWith("QA_") Then

    The message is a bit pointless though except to confirm that the security group QA_Admin exists. If you want all the security groups you want something like this:

    Dim allGroups As List(Of Group) = BRApi.Security.Admin.GetGroups(si)

    Note the return is a list of Group not GroupInfo.

  • sameburn's avatar
    sameburn
    Icon for OneStream Employee rankOneStream Employee

    Hi DK_OS​ 

    It's not too clear what you are trying to achieve based on your code / description?

    But the compiler is telling you that you have created a single GroupInfo object e.g for 1 security group, but you are treating it like a collection e.g > 1 security group and attempting to loop through it and retrieve properties related to Member not Group?

    Also MessageBox.Show isn't valid in onestream (your second error)

    If you want all Groups maybe start with something like this collection

     

     

     

     

     

     

     

     

     

     

     

    You can then do something like this (please log results as you develop to demystify what you are doing, example below)

    Dim objList As List(Of Group) = BRApi.Security.Admin.GetGroups(si)
    
    For Each grp As Group In objList
    
    	If grp.Name.StartsWith("QA_") Then
    		
    		api.LogMessage("Log Group Names that start with QA_", grp.Name)
    	
    	End If	
    	
    Next

    Hope this helps

    Sam

  • sameburn's avatar
    sameburn
    Icon for OneStream Employee rankOneStream Employee

    Not sure why my original comment disappeared...

    But agree with MarcusH​.  Putting it all together would look something like this (please add logging during development to demystify)

    Dim objList As List(Of Group) = BRApi.Security.Admin.GetGroups(si)
    
    For Each grp As Group In objList
    
    	If grp.Name.StartsWith("QA_") Then
    		
    		api.LogMessage("Log Group Names that start with QA_", grp.Name)
    	
    	End If	
    	
    Next

    Also, please be careful working with different object types.  Original code retrieved an object of type GroupInfo but was attempting to loop on MemberInfo (which was not declared). 

  • DK_OS's avatar
    DK_OS
    New Contributor

    Instead of using the API, can i able to pull these details directly from backend data base. i am wondering since this is a cloud based applciation. does it possible?

    • MarcusH's avatar
      MarcusH
      Valued Contributor

      You can access the backend database with cloud applications through the Business Rules. The security groups are held in the Framework database in the table SecGroup which has 4 columns:

      [UniqueID] [uniqueidentifier] NOT NULL
      [Name] [nvarchar](100) NOT NULL
      [Description] [nvarchar](200) NOT NULL
      [XmlData] [nvarchar](max) NOT NULL