Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmdlet "Add-CrmSecurityRoleToUser" & var. "SecurityRoleName" #450

Closed
thuld opened this issue Jan 27, 2021 · 3 comments · Fixed by #451
Closed

Cmdlet "Add-CrmSecurityRoleToUser" & var. "SecurityRoleName" #450

thuld opened this issue Jan 27, 2021 · 3 comments · Fixed by #451
Labels

Comments

@thuld
Copy link
Contributor

thuld commented Jan 27, 2021

Code in cmdlet Add-CrmSecurityRoleToUser is using variable SecurityRoleName but this variable is not correctly handled in the logic.

Calling Add-CrmSecurityRoleToUser with the following parameters does not associate the role

Add-CrmSecurityRoleToUser -UserId $targetUser.systemuserid -SecurityRoleId $_.roleid

The code checks if the value is not an empty string - which is true, becaue the value is NULL.

if($SecurityRoleName -ne "")
    {
        if($UserRecord -eq $null -or $UserRecord.businessunitid -eq $null)
        {
            $UserRecord = Get-CrmRecord -conn $conn -EntityLogicalName systemuser -Id $UserId -Fields businessunitid
        }

@seanmcne seanmcne added the bug label Jan 27, 2021
@seanmcne
Copy link
Owner

Nice catch @thuld! Do you want to submit a PR for this issue?

@mjfara
Copy link

mjfara commented Jan 27, 2021

If anyone needs a workaround in the mean time, you can just assign a global variable with the same name before the call:

    $global:SecurityRoleName = "System Administrator"
    Add-CrmSecurityRoleToUser -conn $conn -UserId $appUser -SecurityRoleId $roleid

@seanmcne
Copy link
Owner

#451

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants