Answered by:
JavaScript error - The value of the property 'OnLoad' is null or undefined, not a Function object

Question
-
I am trying to execute JavaScript in the OnLoad event of a form. Here is my code:
function OnLoad() { var subtotalAttribute = Xrm.Page.getAttribute("new_subtotal"); var subtotalControl = Xrm.Page.getControl("new_subtotal"); var quoteTaxAttribute = Xrm.Page.getAttribute("new_quotetax"); var quoteTaxControl = Xrm.Page.getControl("new_quotetax"); var vendorShippingCostAttribute = Xrm.Page.getAttribute("new_vendorshippingcost"); var vendorShippingCostControl = Xrm.Page.getControl("new_vendorshippingcost"); var clientShippingCostAttribute = Xrm.Page.getAttribute("new_clientshippingcost"); var clientShippingCostControl = Xrm.Page.getControl("new_clientshippingcost"); var quoteTotalAttribute = Xrm.Page.getControl("new_quotetotal"); var quoteTotalControl = Xrm.Page.getControl("new_quotetotal"); // Set all fields to read-only and receive values subtotalControl.setDisabled(true); subtotalAttribute.setSubmitMode("always"); quoteTaxControl.setDisabled(true); quoteTaxAttribute.setSubmitMode("always"); vendorShippingCostControl.setDisabled(true); vendorShippingCostAttribute.setSubmitMode("always"); clientShippingCostControl.setDisabled(true); clientShippingCostAttribute.setSubmitMode("always"); quoteTotalControl.setDisabled(true); quoteTaxAttribute.setSubmitMode("always"); } function new_taxExempt_OnChange() { var taxRateControl = Xrm.Page.ui.controls.get("new_taxrate"); var taxRateAttribute = Xrm.Page.data.entity.attributes.get("new_taxrate"); var taxRateValue = taxRateAttribute.getValue(); var subtotalControl = Xrm.Page.ui.controls.get("new_subtotal"); var subtotalAttribute = Xrm.Page.data.entity.attributes.get("new_subtotal"); var subtotalValue = subtotalAttribute.getValue(); var quoteTaxControl = Xrm.Page.ui.controls.get("new_quotetax"); var quoteTaxAttribute = Xrm.Page.data.entity.attributes.get("new_quotetax"); var quoteTaxValue = quoteTaxAttribute.getValue(); var taxExemptAttribute = Xrm.Page.data.entity.attributes.get("new_taxexempt"); var taxExemptValue = taxExemptAttribute.getValue(); // Calculate Tax Rate if (taxExemptValue == 1) { taxRateAttribute.setValue(00.00); taxRateControl.setDisabled(true); quoteTaxAttribute = taxRateAttribute * subtotalAttribute; Xrm.Page.getAttribute('new_quotetax').setValue(quoteTaxAttribute); } else if (taxExemptValue == 0) { taxRateControl.setDisabled(false); quoteTaxAttribute = taxRateAttribute * subtotalAttribute; Xrm.Page.getAttribute('new_quotetax').setValue(quoteTaxAttribute); } }
When I open the form, I receive this error:
"The value of the property 'OnLoad' is null or undefined, not a Function object".
This is impossible because I have the done the same thing for other web resources and never had this problem. Any ideas?
Thursday, January 26, 2012 1:14 AM
Answers
-
Hi, there is a problem on the line where you have
taxRateAttribute.setValue(00.00);
replace that line with
taxRateAttribute.setValue("00.00");
Regards,
Damian Sinay- Marked as answer by wikky2007 Thursday, January 26, 2012 4:55 AM
Thursday, January 26, 2012 1:52 AM
All replies
-
Hi, have you published the script web resource changes or published all customizations?
Notice that publishing only the form won’t publish the script web resource.
Regards,
Damian SinayThursday, January 26, 2012 1:18 AM -
Yes, I published the web resource. I know I have because removing the second function and only using the first OnLoad works and I receive no errors. Not sure if that means there is something wrong with the second function or not.Thursday, January 26, 2012 1:21 AM
-
The second function appears to be a function that you would call on the onchange of an attribute. Did you link this function with the onchange event of the attribute? function names are case sensitive please check you have used the exact function name in the handler.
HTH
Sam
Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
Thursday, January 26, 2012 1:34 AM -
Hi, there is a problem on the line where you have
taxRateAttribute.setValue(00.00);
replace that line with
taxRateAttribute.setValue("00.00");
Regards,
Damian Sinay- Marked as answer by wikky2007 Thursday, January 26, 2012 4:55 AM
Thursday, January 26, 2012 1:52 AM -
That fixed it! Thanks!Thursday, January 26, 2012 4:55 AM