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

Question

Question

SDK Script To Change Account Password Not Working Consistently

asked on July 23, 2015 Show version history

I have an SDK Script activity that is designed to change an account password if a certain set of requirements are met (in this case the requirement is the Workflow Initiator and the User Account that needs a password change have to be members of the same Group) .  The SDK script works as expected in my VAR kit Avante environment but when I port the workflow to a client's Rio system the SDK script fails.  Here is the code;

        Protected Overrides Sub Execute()
            'Get the username and new password from the template fields...
            Dim userName As String = Me.GetTokenValue("RetrieveFieldValues_UserName")
            Dim newPassword As String = Me.GetTokenValue("RetrieveFieldValues_New Password")

            'Instantiate return status and message...
            Dim success As Boolean = False
            Dim returnMessage As String = ""

            'Wrap in a Try/Catch to catch any errors...
            Try
                'Get workflow initiator name and account, and user account...
                Dim initiatorName As String = Me.WorkflowApi.Initiator.ToString
                Dim initiatorAccount As AccountInfo = Account.GetInfo(initiatorName, Me.RASession)
                Dim userAccount As AccountInfo = Account.GetInfo(userName, Me.RASession)

                'Make sure we are working with a valid user account...
                If userAccount IsNot Nothing Then

                    'Get the user info and groups for both accounts...
                    Dim initiatorInfo As UserInfo = DirectCast(initiatorAccount, UserInfo)
                    Dim initiatorGroups() As String = initiatorInfo.Groups
                    Dim userInfo As UserInfo = DirectCast(userAccount, UserInfo)
                    Dim userGroups() As String = userInfo.Groups
                    Dim found As Boolean = False

                    'Step through the initiator and user groups to find a match...
                    For Each initiatorGroupName As String In initiatorGroups
                        For Each userGroupName As String In userGroups
                            If userGroupName = initiatorGroupName Then
                                found = True
                                Exit For
                            End If
                        Next
                        If found Then Exit For
                    Next

                    'A match was found so change the password and set success flags...
                    If found Then
                        userInfo.Password = newPassword
                        userInfo.Save
                        success = True
                        returnMessage = "Password changed for User " & userName
                        Me.WorkflowApi.TrackInformation(returnMessage)
                    Else    'No match found so set success and message flags...
                        success = False
                        returnMessage = "Initiator " & initiatorName & " and User " & userName & " did not have any groups in common. Password not changed."
                        Me.WorkflowApi.TrackWarning(returnMessage)
                    End If

                End If

            Catch ex As Exception

                'If we threw an error then record it...
                If ex.Message.Contains("9012") Then
                    returnMessage = ex.Message & " User " & userName
                Else
                    returnMessage = ex.Message
                End If

                Me.WorkflowApi.TrackError(returnMessage)
                success = False

            End Try

            'These are the two return tokens from the script.  Use these in conditional logic
            'to change workflow flow and possibly trigger email?
            Me.SetTokenValue("Success", success)
            Me.SetTokenValue("ReturnMessage", returnMessage)

        End Sub

The script apparently fails on this line in Rio and throws a 9012 error (Account not found);

Dim userAccount As AccountInfo = Account.GetInfo(userName, Me.RASession)

In the Avante environment the Account.GetInfo method correctly returns an instance of the AccountInfo.  In the Rio environment the Account.GetInfo method fails to find the account name.  In both systems the account I am looking to retrieve is configured similarly (Not a named user, same rights and privileges, same group memberships)

Any feedback is appreciated...

0 0

Answer

SELECTED ANSWER
replied on July 24, 2015

After stepping through the code a line at a time we determined that the issue was with the line of code that was retrieving the account information for the workflow initiator.  On the Rio system the workflow initiators ended up being LF Trustees not LF Accounts.  In the Avante VAR kit system the workflow initiators were configured as LF Accounts. 

Once I replaced the static Account.GetInfo() method with a static Trustee.GetInfo() the script now works as expected.

Here is the complete script;

        Protected Overrides Sub Execute()
            'Get the username and new password from the template fields...
            Dim userName As String = Me.GetTokenValue("RetrieveFieldValues_UserName")
            Dim newPassword As String = Me.GetTokenValue("RetrieveFieldValues_New Password")

            'Instantiate return status and message...
            Dim success As Boolean = False
            Dim returnMessage As String = ""

            'Wrap in a Try/Catch to catch any errors...
            Try
                'Get workflow initiator name and account, and user account...
                Dim trusteeName As String = Me.WorkflowApi.Initiator.ToString
                Dim trusteeAccount As TrusteeInfo = Trustee.GetInfo(trusteeName, Me.RASession)
                Dim userAccount As AccountInfo = Account.GetInfo(userName, Me.RASession)

                'Make sure we are working with a valid user account...
                If userAccount IsNot Nothing Then

                    'Get the user info and groups for both accounts...
                    Dim acctReference As AccountReference = New AccountReference(trusteeAccount.Sid, Me.RASession)
                    Dim trusteeGroups As AccountReferenceCollection = Trustee.EnumGroups(acctReference, Me.RASession)
                    Dim userInfo As UserInfo = DirectCast(userAccount, UserInfo)
                    Dim userGroups() As String = userInfo.Groups
                    Dim found As Boolean = False

                    'Step through the initiator and user groups to find a match...
                    For Each trusteeGroup As AccountReference In trusteeGroups
                        For Each userGroupName As String In userGroups
                            If userGroupName = trusteeGroup.AccountName Then
                                found = True
                                Exit For
                            End If
                        Next
                        If found Then Exit For
                    Next

                    'A match was found so change the password and set success flags...
                    If found Then
                        userInfo.MustChangePassword = True
                        userInfo.Password = newPassword
                        userInfo.Save
                        success = True
                        returnMessage = "Password changed for User " & userName
                        Me.WorkflowApi.TrackInformation(returnMessage)
                    Else    'No match found so set success and message flags...
                        success = False
                        returnMessage = "Trustee " & trusteeName & " and User " & userName & " did not have any groups in common. Password not changed."
                        Me.WorkflowApi.TrackWarning(returnMessage)
                    End If

                End If

            Catch ex As Exception

                Me.WorkflowApi.TrackError(ex.Message)
                success = False

            End Try

            'These are the two return tokens from the script.  Use these in conditional logic
            'to change workflow flow and possibly trigger email?
            Me.SetTokenValue("Success", success)
            Me.SetTokenValue("ReturnMessage", returnMessage)

        End Sub

 

1 0

Replies

replied on July 23, 2015

If you try to hard code a test name does this still produce an error? If not and it is able to find the user check the tokens that are being pushed in the SDK script. I am to assume that you are using this SDK script in workflow correct? If so during a run you can check the tokens that get recorded and verify they have correct values.

0 0
replied on July 23, 2015

Yes, hard-coding the values still produces the error on the Rio system.  Tracked tokens all appear to have normal values.  Even verified that the account that WF is running under on the Rio server had all privileges checked.

0 0
replied on July 23, 2015

Any one? 

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

Sign in to reply to this post.