Friday, 13 April 2012

Assign a Record to a Team or User in CRM 2011

In this article , I am explaining how to assign a record to specific user or team using AssignRequest class
 public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
 {
     OrganizationServiceProxy _serviceProxy;
     using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,
                  serverConfig.HomeRealmUri,
                  serverConfig.Credentials,
                  serverConfig.DeviceCredentials))
     {
        _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

         _service = (IOrganizationService)_serviceProxy;

         Guid _accountId = new Guid("4d36e97d-e325-11ce-bfc1-08002be10318");
         Guid _teamId = new Guid("5d46e97d-f325-33ce-cdc1-09002be10318");

         // Assign the account to a team.
         AssignRequest assignRequest = new AssignRequest()
         {
             Assignee = new EntityReference
             {
               LogicalName = Team.EntityLogicalName,
               Id = _teamId
              },
             Target = new EntityReference(Account.EntityLogicalName, _accountId)
         };

          _service.Execute(assignRequest);

    }

}

No comments:

Post a Comment