Thousand
Thousand

Reputation: 6638

fireOnChange does not fire dynamics crm 2011

I have a javascript webresource in a crm2011 Contact form. Under the form properties of the form, i added the Form_onload() function below to the OnLoad event handler. When i debug it, i can see that the Form_onload() method is being fired and executed.

However, when I try to edit the mobilePhone number and i click out of the field, i get nothing. When i debug, the breakpoint inside the mobilephone_OnChange() method is not hit, it simply does not do a thing.

function Form_onload()
{
Xrm.Page.getAttribute("mobilephone").fireOnChange();
}


function mobilephone_OnChange()
{
alert("fire away");
}

All what I want to do is, get the little alert inside the mobilephone_OnChange() function.

I seriously dont know what to do anymore. I've read tons of articles stating that .fireOnChange() will automatically wire up all OnChange events that are declared. However, this doesn't seem to work.

Upvotes: 2

Views: 10393

Answers (2)

Daryl
Daryl

Reputation: 18895

Try this:

Xrm.Page.getAttribute("mobilephone").addOnChange(this.mobilephone_OnChange);

depending on how you've structured your js file, "this" maybe the name of your js class.

Also note that if you update the field programmatically in Javascript, the onChange event will not fire automatically. (But can be via FireOnChange())

Upvotes: 5

James Wood
James Wood

Reputation: 17552

I think you have this the wrong way round.

fireOnChange doesn't register a function on an on change event - it creates an event which will fire any registered function.

I think what you need to do is register mobilephone_OnChange() to the field, either via the UI or if you want to do it programmatically use addOnChange.

Upvotes: 4

Related Questions