locked
CRM2011 update entity by program RRS feed

  • Question

  • Hi all

    I have some problem that need your help......

    One of our client want to update their accounts owner. due to the large amount of accounts, he request if we can provide him a program or a function to do so.

    But I found that, I cannot update the ownerid in the database directly...

    may I ask how can I update the ownerId by program please?

    please advise or comment, many thanks.

    Monday, August 6, 2012 4:27 AM

Answers

  • You can try to use CRM Workflows directly - there is a step called "Assign".


    Or you can write small desktop/ASP.NET app and change account owner using AssignRequest class.

    Here small example

    // Create the Request Object and Set the Request Object's Properties
    AssignRequest assign = new AssignRequest
        {
            Assignee = new EntityReference(SystemUser.EntityLogicalName,
                _otherUserId),
            Target = new EntityReference(Account.EntityLogicalName,
                _accountId)
        };
    
    
    // Execute the Request
    _service.Execute(assign);

    Please take a look at CRM SDK for more examples:

    SDK\samplecode\cs\generalprogramming\earlybound\assign.cs
    SDK\samplecode\cs\generalprogramming\earlybound\assignrecordtoteam.cs

    Here some basic code to connect with CRM from extern apps using IOrganizationService Interface and OrganizationServiceProxy class :

    Uri organizationUri = new Uri(@"http://crm/_organizationname_/XRMServices/2011/Organization.svc");
    Uri _homeRealmUri = null;
    IOrganizationService _service;
    string _userName = "username";
    string _password = "pass";
    string _domain = "domain";
    
    var credentials = new ClientCredentials();
    credentials.Windows.ClientCredential = new NetworkCredential(_userName, _password, _domain);
    var orgService = new OrganizationServiceProxy(_organizationUri, _homeRealmUri, credentials, null);
    orgService.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
    
    _service = (IOrganizationService)orgService;

    • Proposed as answer by toLL_net Monday, August 6, 2012 7:30 AM
    • Marked as answer by Ksun_Chan Monday, August 6, 2012 10:02 AM
    Monday, August 6, 2012 7:28 AM

All replies

  • You can try to use CRM Workflows directly - there is a step called "Assign".


    Or you can write small desktop/ASP.NET app and change account owner using AssignRequest class.

    Here small example

    // Create the Request Object and Set the Request Object's Properties
    AssignRequest assign = new AssignRequest
        {
            Assignee = new EntityReference(SystemUser.EntityLogicalName,
                _otherUserId),
            Target = new EntityReference(Account.EntityLogicalName,
                _accountId)
        };
    
    
    // Execute the Request
    _service.Execute(assign);

    Please take a look at CRM SDK for more examples:

    SDK\samplecode\cs\generalprogramming\earlybound\assign.cs
    SDK\samplecode\cs\generalprogramming\earlybound\assignrecordtoteam.cs

    Here some basic code to connect with CRM from extern apps using IOrganizationService Interface and OrganizationServiceProxy class :

    Uri organizationUri = new Uri(@"http://crm/_organizationname_/XRMServices/2011/Organization.svc");
    Uri _homeRealmUri = null;
    IOrganizationService _service;
    string _userName = "username";
    string _password = "pass";
    string _domain = "domain";
    
    var credentials = new ClientCredentials();
    credentials.Windows.ClientCredential = new NetworkCredential(_userName, _password, _domain);
    var orgService = new OrganizationServiceProxy(_organizationUri, _homeRealmUri, credentials, null);
    orgService.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
    
    _service = (IOrganizationService)orgService;

    • Proposed as answer by toLL_net Monday, August 6, 2012 7:30 AM
    • Marked as answer by Ksun_Chan Monday, August 6, 2012 10:02 AM
    Monday, August 6, 2012 7:28 AM
  • Hi and thanks for your reply, it is the way ! thank you.
    Monday, August 6, 2012 10:02 AM