CRM 2011 – Form is always dirty – Trailing spaces

With CRM 2011, whenever you want to automatically refresh or save a form that has supposedly not been modified by a user, and still get that annoying “Are you sure you want to leave” message, you can sometimes start getting a bit upset about it. Xrm.Page.data.entity.getIsDirty() always returns true. But the form was just loaded! And no javascript in there updates a field. What’s happening?

Well, don’t get too upset, it’s not worth it! Well, after all, maybe it is…

It turns out that on one of my forms, one field was sometimes dirty. That field was a lookup. Actually, the field’s dirtyness depended on the referenced record: it was always dirty with this record, and never with another one. After looking carefully at the referenced record, it turned out we were facing the dreaded “blank space” issue, and particularly the “trailing space” one. That record’s name actually had a trailing space in it! For some… dirty reason, CRM thinks it’s a good idea to actually remove trailing spaces from lookup names, and by that to make these lookups dirty when nothing actually changed…

Of course, when opening the guilty record, you just can’t remove the trailing space, as CRM will ignore that change and thus will not save it. You need to change something more to actually save the record, and then reset it…

According to me, this behavior is a bug and should be corrected asap.

Leave a Reply

Your email address will not be published. Required fields are marked *