Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Error:Entity Id must be specified for Update C# CRM 2016

Posted on by Microsoft Employee

Hi I'm using this code and its giving me an error: entity id must be specified for update,

Any help?

private void button3_Click(object sender, EventArgs e)
{
// Update the fetched record
Entity new_Child = new Entity("new_child");

//new_Child.Attributes["new_fullname"] = "joy";

new_Child.Attributes["new_age"] = 6; 

new_Child.Attributes["new_weight"] = (decimal)15; //

new_Child.Attributes["new_height"] = (double)25;


_service = GetService();


Guid g = _service.Create(new_Child);


var cols = new ColumnSet(new[] { "new_age", "new_weight", "new_height" });

_service.Update(new_Child);


}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error:Entity Id must be specified for Update C# CRM 2016

    It worked, but I wasn't clicking on the create button when I build and start running the code.

    Thank you for replying and your time..

    I used this line columnSet to verify what are the fields that I need to update

  • Indika Abayarathne Profile Picture
    Indika Abayarathne 671 on at
    RE: Error:Entity Id must be specified for Update C# CRM 2016

    Yes, Only one argument, which is newChild. But in the newChild you need to have Id to identify the correct record.

    After you create the record you have the UniqueIdentifier of the record which is "g".

    You can update teh record like this;

    new_Child.Attributes["new_age"] = 10;

    new_Child.Attributes["id"] = g;

    _service.Update(new_Child);

    msdn.microsoft.com/.../gg328416.aspx

  • Suggested answer
    RE: Error:Entity Id must be specified for Update C# CRM 2016

    hi,

    you need to add id to new_child object

    like:

    new_Child.Id= g;

    _service.Update(new_Child);

    Can you explain this line why are using this:

    var cols = new ColumnSet(new[] { "new_age", "new_weight", "new_height" });

  • Suggested answer
    Dynamics_Alok Profile Picture
    Dynamics_Alok 1,746 on at
    RE: Error:Entity Id must be specified for Update C# CRM 2016

    Yes ..Update takes one argument and in your case ,it is new_Child,but new_Child should contain id attribute.

    Like var new_Child = new Entity("LogicalName");

    new_Child.Id = "Guid of record",

    new_Child["dsadsd"] = "dsadff" ; etc

    and then _service.Update(new_Child); but new_Child.Id = "Guid of record" is most.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error:Entity Id must be specified for Update C# CRM 2016

    But update I can't put inside the parameter of update more than 1 arg.

    you mean to change this line:

    _service.Update(new_Child);

    into:

    _service.Update(new_Child,g,cols); ??

    if yes, its not working !! I don't know if I get you right. Thanks for your time and your answer

  • Indika Abayarathne Profile Picture
    Indika Abayarathne 671 on at
    RE: Error:Entity Id must be specified for Update C# CRM 2016

    When you are Updating any record, you need to specify the UniqueIdentifier. Otherwise how does CRM (or any other system) know the record that you are targeting?

    //You get the Service Here;

    _service = GetService();

    //Create the new record using "new_Child" Object.= get the ID to "g"
    Guid g = _service.Create(new_Child);

    //Still "new_Child" has only, "new_age", "new_weight", "new_height"

    // You get col object but never using
    var cols = new ColumnSet(new[] { "new_age", "new_weight", "new_height" });

    // You update the the same "new_Child" object with no Id. It has only "new_age", "new_weight", "new_height".

    _service.Update(new_Child);

    // You should add the "Id" to "new_Child" object with the value in "g". And then update.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans