0
votes

I have found many sample to create data in dynamics crm from a custom aspx page, but i need to update entity data. any sample will be helpful.

Thanks

1

1 Answers

2
votes

It's quite simple, when you create a record normally you use the following code:

Entity newContact = new Entity("contact");
contact["firstname"] = "John";
contact["lastname"] = "Smith";
service.Create(newContact);

If you need to update a record, you need to retrieve it first (using a Retrieve if you have the Guid, or a RetrieveMultiple if you need to find it using a query), after just update the fields.

Entity retrievedContact = service.Retrieve("contact", GuidOfTheRecord, ColumnsYouWantToRetrieve);
retrievedContact["firstname"] = "My New First Name";
retrievedContact["lastname"] = "My New Last Name";
service.Update(retrievedContact);