Tuesday, June 12, 2012

CRM 2011 User does not have send-as privilege



CRM 2011 User does not have send-as privilege

When you have workflows in CRM 2011 that create e-mails for other users, like say, send an e-mail from the person who last modified an account to the owner of the account, you’re probably going to end up with e-mails staying in Draft.
When you want to send the e-mail afterwards you’re greeted with a nice: “User does not have send-as privilege.” (ErrorCode: -2147203059) exception.
When you look up the privilege, it’s nowhere to be found in the UI.
You can however set it (as suggested on the Microsoft Forum) in the Personal Settings.


The downside, you only get this option when you have the System Administrator role and no other.
When looking in the database, there is actually a prvSendAsUser privilege, so after assigning it to a general role that all users get like this:
AddPrivilegesRoleRequest addPrivilegesRequest = new AddPrivilegesRoleRequest
{
RoleId = new Guid(generalroleid),
Privileges = new[]
{
// Grant prvSendAsUser privilege.
new RolePrivilege
{
PrivilegeId = new Guid("6FD3EB4F-66E3-4587-B4AB-C064F03AD783"),
Depth = PrivilegeDepth.Global
}
}
};
service.Execute(addPrivilegesRequest);
If you afterwards have a look at the user’s privileges in the database with this query:
SELECT p.name
FROM SystemUser u
JOIN filteredSystemUserRoles sur ON sur.systemuserid = u.systemuserid
JOIN RolePrivileges rp ON rp.roleid = sur.roleid
JOIN FilteredPrivilege p ON p.privilegeid = rp.PrivilegeId
You’ll see that the user has in fact got the prvSendAsUser role.
But when you try to send an e-mail the problem stays the same.
The solution however is very simple, check for this privilege is not done in through privileges, despite what the exception makes you suggest, but is checked in the user settings.
Running an easy update query will fix this for you:
UPDATE UserSettings
SET IsSendAsAllowed = 1
WHERE IsSendAsAllowed = 0
Logical, no; but does it work, yes