Skip to content

Find and Update the Default Organization For a User in CRM 2011

May 31, 2012

Note: This is not a Microsoft recommended approach as it directly updates the database and is therefore not supported.
The script below has been floating around for a few months in various incarnations, I cleaned it up and made it a little more readable and reusable (at least that was my goal). I don’t take credit for finding this only for modifying the script to be a little more user friendly. (WordPress modifies the text so when you paste this, the ‘ may show up as ` and need to be replaced. Once I figure out how to fix that I will do so. Also the double hyphen for comments comes out as a single – hence the /* */ around all single line comments.

/*Find the default organization for a user*/
@DomainName nvarchar(255)
,@OrgCRMDBName varchar(255)
,@SystemUserId uniqueidentifier
,@SQLString nvarchar(500)
,@ParmDefinition nvarchar(500)

/*Configure the @Domainname and @OrgCRMDBName values*/
SET @DomainName        = ‘<domain>\<user>’ –Set this to the domain\user you want to find
SET @OrgCRMDBName = ‘<ORG>_MSCRM’ –Set this to the ORG_MSCRM DB Name

/*Do not change these*/
SET @SQLString            = N’SELECT @SystemUserIdOUT = SystemUserId FROM ‘ + @OrgCRMDBName + ‘..SystemuserBase WHERE DomainName = ”’ + @DomainName + ””;
SET @ParmDefinition = N’@SystemUserIdOUT uniqueidentifier OUTPUT’;

EXEC sp_executesql @SQLString, @ParmDefinition, @SystemUserIdOUT=@SystemUserId OUTPUT;

/*Identify the DefaultOrganization and settings for a given user*/
                     FROM MSCRM_CONFIG..SystemUserOrganizations
                     WHERE CRMUserId = @SystemUserId )

/*Find the organizations that have been created.*/

/*Update the organization for a given user*/
UPDATE SystemUser SET DefaultOrganizationId = ‘<NewOrgId>’ WHERE Id = ‘<UserId>’

If you are not comfortable doing this directly to the database Mohammad Atif has another method that will work and is described here


From → CRM 2011, SQL Server

One Comment
  1. Ganesh Sivakumar permalink

    If you want to enable one organization to be default for all the users, the first enabled organization will be used. So disable all the org and enable the organization which you want to be default for all the users.

    This is useful when you have to switch the users between pilot and production. Sometimes it’s useful to have the users running on pilot when there is a new change or when the production is taken down for maintenance. 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: