Microsoft Dynamics 365 : IOrganizationService.Update(Entity) Method

Here’s a quick guide covering the IOrganizationService.Update(Entity) method

Update method is part of the IOrganizationService interface , it is used to update an entity record and in order to access it you need the Microsoft.Xrm.Sdk namespace in your program. You can use the update method in early bound or late bound but in order to do that you must be connected to the server to instantiate an IOrganizationService interface

Message Availability

This message works regardless whether the caller is connected to the server or offline but not all entity types support this message offline.

Privileges and Access Rights

To perform this action, the caller must have privileges on the entity and access rights on the record specified in the Update(Entity) parameter.. For a list of the required privileges, see Update message privileges.

Notes for Callers

If the entity instance includes properties that are not valid for update, they are ignored. You can find this information in the metadata for your organization.

You can use this method to update any record of an entity that supports the Update message, including custom entities.

For more information about the exceptions that can be thrown when this method is called, see Handle exceptions in your code.

 

The method’s syntax:

Update(Entity);

 

Example:

In the example below I use the Update method to update a specific field in a custom entity (customer) , we’ll go through it and explain every step which is signed with a number :

  1. I use the Retrieve method to retrieve the specific field I need to use from the custom entity ‘Customer’ , the field I retrieve with this line of code is the ‘fisoft_revenue’ field
  2. Then I get the value of the ‘fisoft_revenue’ field which in our case it is a currency type field (Money keyword in front means that) , after getting the value I convert it into a decimal value and then use it to calculate the Sum of this value and another value (think of it as any decimal value just so our example makes sense) , after getting the decimal Sum I convert this sum from Decimal to Money (currency field format) so I can use it later to update our field
  3. I declare a variable ‘UpdateRev’ which in our case its basically the specific customer we retrieved earlier
  4. In this next line of code , I make our ‘fisoft_revenue’ field equal to our converted Sum that we got earlier
  5. And in the last line of code I use the Update method to update the ‘UpdateRev’ entity , after this line of code the current value of the field gets changed with the new value from our calculations.