We have recently migrated to CRM 2016 SP1 from CRM 2015. We have read that in the new version SetState requests are starting to be deprecated and that it is advised to use Update requests instead. According to the documentation if you send an Update request including a state/status fields and some regular fields, your update plugins should fire twice: once for the state/status fields and then for the regular fields.
However, what we've observed on several of our entities is that in such a scenario, an update plugin is indeed fired twice, but the attributes in the Target don't match the documentation. One run contains state/status fields only (and some additional fields like id and modifiedby, that were not part of the update) and second one contains ALL of the fields that were included in the update (including state/statecode).
This is not according to the documentation and we have plugins fired twice for state/statuscode fields and there's no way to differentiate if a certain request has already been handled. This breaks a lot of our custom code.
Here's an example:
var record = new Entity("affiliation"); record.Id = new Guid("889D5442-6719-E411-RW94-005056817123"); record["statecode"] = new OptionSetValue(1); record["statuscode"] = new OptionSetValue(125080000); record["name"] = "abc 01"; svc.Update(record);
Pre-operation plugin runs' attributes:
- first: statecode, statuscode, name, modifiedby, modifiedon, modifiedonbehalfby, affiliationid
- second: statecode, statuscode, modifiedby, modifiedon, modifiedonbehalfby, affiliationid
I haven't found anyone complaining about such a behaviour over the internet and I'm wondering if this is by design or a known bug of CRM or has it only happened to us? Or does it have something to do with SP1? We wouldn't like to invest in workarounds if this is something that can be/will soon be fixed.