CRM 2011: Fields updated during PostRetrieve not saving when Form is saved
I have some code in a PostAccountRetrieve (i've removed lines):
Entity entity = (Entity)localContext.PluginExecutionContext.OutputParameters["BusinessEntity"];
Account account = entity.ToEntity();
...
account.test_TerminationDate = DateTime.SpecifyKind((DateTime)subscriber.TerminationDate, DateTimeKind.Local);
account.test_MaxPositions = su开发者_如何学Cbscriber.MaxLivePos;
account.test_Locked = subscriber.Locked;
entity.EntityState = Microsoft.Xrm.Sdk.EntityState.Changed;
...
The fields on the form are filled in by the code, however, when the user presses "Save", it does not save these values with the account. I thought setting the EntityState would take care of this. What am I missing?
I don't think EntityState will help you in a Post Retrieve plugin. I'm pretty sure your problem is that the CRM form is smart enough to only submit values that were actually changed. You are "changing" these values in Post Retrieve, which happens as the form loads, so the form doesn't think these values have changed and doesn't submit them when you click Save.
The solution is to use this javascript in the form load:
Xrm.Page.getAttribute(“test_TerminationDate”).setSubmitMode(“always”);
Xrm.Page.getAttribute(“test_MaxPositions”).setSubmitMode(“always”);
Xrm.Page.getAttribute(“test_Locked”).setSubmitMode(“always”);
This should bypass CRM's "smarts" so those fields always get submitted on Save.
精彩评论