SDK.REST.updateRecord Gotcha

If you're using SDK.REST.updateRecord to update a record in CRM, ensure that the object you pass contains the minimum number of attributes needed. Poor practice would be to retrieve the entity record in its entirety and then update certain attributes. For example, the following code retrieves an entire entity with all of its attributes:

Subsequently updating properties of the record variable and calling SDK.REST.updateRecord will not just update the attributes you've set, but all attributes.

The code above changes the record's Name to "A new name". When updateRecord is called, all attributes are updated, even though all attributes except for Name are just being overwritten with what they already were. This is a nuisance because:
  • Workflows which trigger on update of a field will trigger unnecessarily.
  • An unwanted performance overhead is incurred.
  • The executing user may have permission to update the record's Name but not access to update fields which may be secured fields. The update will therefore fail.

No comments:

Post a Comment