locked
Dynamics CRM Online CRUD Operation using console application RRS feed

  • Question

  • I want to do CRUD Operation on account entity. And I have already created 1 record successfully using hard coded value. below is my sample code

     public static void Main(string[] args)
            {
                //create service crm
                CrmServiceClient crmConn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM"].ConnectionString);
                IOrganizationService crmService = crmConn.OrganizationServiceProxy;

                //First tutorial CRUD Crm 2011
                // 1. Create
                Entity acc = new Entity("account");
                acc["name"] = "Google Account";
                acc["telephone1"] = "9876543223";
                acc["websiteurl"] = "www.google.com";
                crmService.Create(acc);      

            }

    Now I want to retrieve and update the same record using GUID. can anyone please help me with this?

    Thanks...!!!

    Monday, November 13, 2017 2:15 PM

Answers

  • retrieve

    crmService.Retrieve(acc.LogicalName, acc.Id,new ColumnSet(true));

    update

     acc["attribute name"] = "value";//set value 

    crmService.Update(acc);


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Proposed as answer by Mr. Santosh Bhagat Wednesday, November 15, 2017 6:11 AM
    • Marked as answer by MS_User_007 Wednesday, November 15, 2017 6:51 AM
    Wednesday, November 15, 2017 6:11 AM
  • acc.Attributes["name"].ToString() -- This can be used in writeline method to show data retrieved.

    Make sure you check for the field value before you use above.

    acc.Attributes.Contains("name"). If name field has no value, you endup not retrieving it.


    Jugal Kishore Dandamudi.

    • Marked as answer by MS_User_007 Wednesday, November 15, 2017 9:15 AM
    Wednesday, November 15, 2017 9:11 AM

All replies

  • retrieve

    crmService.Retrieve(acc.LogicalName, acc.Id,new ColumnSet(true));

    update

     acc["attribute name"] = "value";//set value 

    crmService.Update(acc);


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    • Proposed as answer by Mr. Santosh Bhagat Wednesday, November 15, 2017 6:11 AM
    • Marked as answer by MS_User_007 Wednesday, November 15, 2017 6:51 AM
    Wednesday, November 15, 2017 6:11 AM
  • Thanks Santosh. I have done the same coding for retrieve and update. 

     ColumnSet attributes = new ColumnSet(new string[] { "name", "telephone1", "websiteurl" });
     // Retrieve the account and its name, telephone and website URL attributes.
     acc = crmService.Retrieve(acc.LogicalName, CR._accountId, attributes);
      Console.Write("Data retrived  : " );

    I just want to know how to display that retrieved data? what parameters should go in console.writeLine?


    • Edited by MS_User_007 Wednesday, November 15, 2017 7:45 AM spelling corrections
    Wednesday, November 15, 2017 6:51 AM
  • acc.Attributes["name"].ToString() -- This can be used in writeline method to show data retrieved.

    Make sure you check for the field value before you use above.

    acc.Attributes.Contains("name"). If name field has no value, you endup not retrieving it.


    Jugal Kishore Dandamudi.

    • Marked as answer by MS_User_007 Wednesday, November 15, 2017 9:15 AM
    Wednesday, November 15, 2017 9:11 AM
  • Thanks Jugal
    Wednesday, November 15, 2017 9:15 AM
  • The other suggestions are not correct because nobody is catching the Guid value.

    //First tutorial CRUD Crm 2011
                // 1. Create
                Entity acc = new Entity("account");
                acc["name"] = "Google Account";
                acc["telephone1"] = "9876543223";
                acc["websiteurl"] = "www.google.com";
    var accountId = crmService.Create(acc);     

    //Retrieve

    var retrievedAccount = crmService.Retrieve("account", accountId, ColumnSet(true)); //ColumnSet(true) is not the most optical way.

    update

    var updateAccount = new Entity("account");

    updateAccount.Id = accountId;

     updateAccount.Attributes.Add("name", "Microsoft"); 

    crmService.Update(updateAccount);

     


    • Edited by MGCRM Saturday, November 18, 2017 9:29 PM
    • Proposed as answer by MGCRM Saturday, November 18, 2017 9:30 PM
    Saturday, November 18, 2017 9:28 PM