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

Question

Question

Using SDK Script to add a Windows user to a repository group

asked on June 22, 2023

I am trying to implement a form that will allow a department to manage who can view certain folders.  As part of that process I'm trying to implement a workflow that will add a Windows user to a repository group.  The workflow fails to add the user with the warning "Trustee not found. [9012]"

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports Laserfiche.RepositoryAccess

Namespace WorkflowActivity.Scripting.SDKScriptAddUserToLFGroup
    '''<summary>
    '''Provides one or more methods that can be run when the workflow scripting activity is performed.
    '''</summary>
    Public Class Script1
        Inherits RAScriptClass104
        '''<summary>
        '''This method is run when the activity is performed.
        '''</summary>
        Protected Overrides Sub Execute()
            'Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
            Dim inUserID As String = GetTokenValue("inUserID")(0)
            Dim inGroupName As String = GetTokenValue("inGroupName")(0)
            Dim inGroupAcct As AccountInfo = Account.GetInfo(inGroupName, RASession)
            Dim inUserAcct As AccountReference = New AccountReference(inUserID, RASession)
            Dim UserGroup As GroupInfo = CType(inGroupAcct, GroupInfo)
            UserGroup.AddMember(inUserAcct)
            UserGroup.Save
        End Sub
    End Class
End Namespace

It works fine... if I don't execute the Save :)

0 0

Replies

replied on June 22, 2023

You screenshot doesn't show what generates inUserID and inGroupName tokens. Are you sure they're not empty?

 

0 0
replied on June 22, 2023

Miruna, Yes, they are valid.  They come in as input parameter tokens.  I wouldn't share them on a public forum.

0 0
replied on June 22, 2023

The error looks correct though. I get it regardless of the presence of userGroup.Save. It looks to be caused by "(0)" in the definition of inUserID and inGroupName making them return just the first letter of the string passed in from the parameter.

You can add  WorkflowApi.TrackInformation(inUserID) to get WF to record values to the instance details as messages.

All that stuff before the script is unnecessary. AddMember won't throw an error if the user is already a member, so you can always add it. It will be more efficient than looping through all group members to check if it already exists in the group.

0 0
replied on June 23, 2023

Thanks for the efficiency advise.  You're correct about the subscript on the string if it is for a simple string token, but for an input parameter the subscript refers to the first string (even though there is only one string in the array).  I've dumped the name of the retrieved user (as a token value) and it is correct.  Thanks also for the information about the TrackInformation method; I wasn't aware of that.

0 0
replied on June 23, 2023

I went back and double checked.  This code works fine for a repository named user, but fails on a Windows account.  The AccountReference AccountName property is correct, so the instantiation of the AccountReference object seems to have been successful.  The GroupInfo.Name property is correct after the GetInfo and type conversion.  It seems like the AddMember method simply cannot find and validate a Windows account.

0 0
replied on June 23, 2023

Does the Windows account in question show up in the repository admin console? If not, maybe try testing with an account that is listed there.

I could be mistaken since it has been a while, but I seem to remember having a similar issue with Windows accounts where I had to add the account as a trustee before I could add them to groups.

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

Sign in to reply to this post.