Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Wednesday, May 23, 2012

Changing CRM form properties in Javascript doesn't trigger onChange

I've just learnt the hard way that when you change a field value on a MS CRM 2011 form via JavaScript it doesn't automatically trigger any onChange event which is wired up to that field.
To manually trigger any onChange event you do the following


Xrm.Page.getAttribute('myfieldname').fireOnChange();


or better yet, if you use a custom library to simplify your read


SetAttributeValue = function (attributeString, value) {
 var attribute = Xrm.Page.getAttribute(attributeString);
 
 if (attribute) {
  attribute.setValue(value);
  // manually fire the onChange event.
  attribute.fireOnChange();
 }
};