You are viewing limited content. For full access, please sign in.

Question

Question

Join LFDS user to a group using the License Manager Object (LMO) in WF

asked on May 11, 2021

I am looking to join a LFDS user to a LFDS group. I have the LMO documentation. It has no examples of this. I looked through the API, but when I try it out, I get errors such as Value cannot be null or other such errors. I was able to create the user, get the group, but cannot seem to join the two.

The code that I use to create the user is as follows.

' Login to the Directory Server.
Dim server As Laserfiche.LicenseManager.LMO.Server = Laserfiche.LicenseManager.LMO.Server.Connect(sDirectoryServerHostName, False)
Dim db As Database = server.GetDatabaseByRealmName(sLicensingSiteName)
db.LoginWindows()

' Is the user already created?
Dim LFDSUser As LaserficheUser = LaserficheUser.Create(db)

' Need to create the user.
LFDSUser.ContainerID = GetOrganizationbyName(sOrganizationName, db)
LFDSUser.MfaRequired = False
LFDSUser.Name = sUsername
LFDSUser.Password = sPassword
LFDSUser.Enabled = True

I created a supporter function, Get Group as I do not have the SID or ID of the group to use the Database.GetGroup() function. The supporter function is as follows.

        Function GetGroup(sGroupName As String, db As Database, sOrganizationName As String) As Group
            Dim retval As Group = Nothing
            Try 
                Dim nContainerID As Integer = GetOrganizationbyName(sOrganizationName, db)
                Dim groups As List(Of Group) = db.GetGroupsByContainer(nContainerID)
                For Each oGroup As Group In groups
                    If oGroup.Name = sGroupName Then
                        retval = oGroup
                        Exit For
                    End If
                Next
            Catch ex As Exception

            End Try
        
            Return retval
        End Function

I did that because I see that the Group object has a GetMembers() function and SetMembers() method.

After that I tried the GetMembers() function and was able to get the members with the following code:

Dim group As Group = GetGroup("Test", db, sOrganizationName)
Dim members As Dictionary(Of String, String) = group.GetMembers()
For each member As Object In members
	MsgBox( member.ToString() )
Next

This resulted in the result [sid, name]

Next I tried to add a member to the members list using:

members.Add(LFDSUser.SIDString, LFDSUser.Name)

This resulted in the error message Value cannot be null. Parameter name: key.

0 0

Answer

SELECTED ANSWER
replied on May 11, 2021

Here's an example in C#

            var newMembers = new List<string>();

            // get current members
            var currentMembers = group.GetMembers();

            // check if member not in group
            if (!currentMembers.ContainsKey(user.SIDString))
            {
                // get current members
                if(currentMembers.Any())
                {
                    newMembers.AddRange(currentMembers.Select(x => x.Key).ToList());
                }

                // add new member
                newMembers.Add(user.SIDString);
                group.SetMembers(newMembers);
                group.Update();
            }

 

2 0
replied on May 11, 2021 Show version history

Thanks Jason. Just having one issue with it.

I translated the C# to VB so I would not have to rewrite everything else. I also left out the portion that checks if the user is already in the group as they were just created. That puts the code to:

Dim newMembers As List(Of String) = New List(Of String)

' get current members
Dim currentMembers As Dictionary(Of String, String) = group.GetMembers()

' add current members
For Each member As KeyValuePair(Of String, String) In currentMembers
	newMembers.Add(member.key)
Next

' add new member
newMembers.Add(LFDSUser.SIDString)
group.SetMembers( newMembers )
group.Update()

I did get this to work.

0 0

Replies

replied on May 11, 2021

Hi Michael,

I am not positive on the VB syntax, but to add a user to a group in C# you would do it like so:

group.SetMembers(new List<string>() { LFDSUser.SIDString });

 

replied on September 3, 2022

Can someone point me in the direction of how to use these scripts in a Workflow? What are the required variables

0 0
replied on September 6, 2022

Jonathan,

What are you trying to do?

In my original post I was trying to join an LFDS user to a group using License Manager Objects in Workflow.

This is done in an SDK Script. It took me quite a while to figure out some of the setup and required classes. I think I had a couple cases with Laserfiche as well.

If this is your first time working with LFDS in the SDK Script, I suggest talking with your VAR to make sure you are on the newest Work Flow version. Older versions of Work Flow have issues with some of the libraries. You will need to include the LicenseManagerObjects and import the Laserfiche.LicenseManager.LMO and Laserfiche.LicenseManager.LMO.DirectoryServices. If you are not using LFDS, there are other answer pages that can go into those.

If you are needing to create the user like I did, you can use the code at the very top. It requires the Directory Server Host Name, the Licensing Site Name, the Organization Name, a Username, and Password. I used the variable LFDSUser. You will need to add some references for this to work. You can do some tweaking to the code if you want different behavior, such as MFA.

Next you will want to get the Group. You should be able to do this with the GetGroup function that I included as well. For this you need the group name and the organization name.

Finally you will want to add the user to the group. I tried to add the other way because of how the LFSO had it used.

Also, keep in mind that you do need to have the proper licenses for each user created.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.