24 November 2010

Import Organisation, change to default, gives Invalid User Authorization Error

When importing an organisation into Dynamics CRM 4.0 and making it default you sometimes come across the "Invalid Authorization error" message even though you're logged in as the System Administrator.

The following TSQL should be run on the SQL instance that hosts the CRM databases. It isn't a supported fix and I take no responsibility if it breaks your system. Remember backups are your friend!

The scripts have been taken from other resouces on the t'internet, but I can't remember where. When I find out I will acknowledge the original authors hard work.

-- Import Organisation, change default, gives Invalid User Authorization error
-- To Resolve this issue it is necessary to change the user's default organisation

--STEP 1
DECLARE @Org nvarchar(50)

DECLARE @OrgDb nvarchar(150)
set @OrgDb= @Org + '_MSCRM'

DECLARE @UserName nvarchar(50)
set @UserName='DOMAIN\username'

execute ('select OrganizationId from ' + @OrgDb +'..organization where name=''' + @Org +'''')
execute ('select systemuserid, DomainName from ' + @OrgDb +'..SystemUserBase where DomainName='''+ @UserName + '''')

--STEP 2
-- User the systemuserid returned to get the correct GUID
select userid from MSCRM_CONFIG..systemuserorganizations where crmuserid = '[systemuserid]'

-- Use the userid to return the correct
select DefaultOrganizationId from MSCRM_CONFIG..systemuser where id = '[userid]'

--Use the DefaultOrganizationId and userid to update the table
update MSCRM_CONFIG..systemuser set defaultorganizationid = '[DefaultOrganizationId]' where id = '[OrganizationId]'

No comments:

Post a Comment