"Object doesn't support property or method 'getAttribute'"

Chris76786777 picture Chris76786777 · Oct 15, 2012 · Viewed 9.7k times · Source

I'm working with Dynamics CRM 2011 Online and trying to refactor some code that works on the Quote > Add Product page to also work on Order > Add Product. The problem is that when the page loads I get the error "Unable to get property 'getValue' of undefined or null reference."

I went into the IE console (tried both IE 9 and 10) and typed in what I believed to be the offending line:

Xrm.Page.getAttribute('ati_clin').getValue()

It complains with "Object doesn't support property or method 'getAttribute'". I also tried

document.getElementById('ati_clin')

but that too fails.

This doesn't make sense to me because I can use the HTML view of the developer console to find the object on the page and it's clearly there (no typo too). It also doesn't make sense that this statement fails in the console on both pages even though one of the pages runs properly at runtime and the other doesn't. Shouldn't it at least work on the page that does work at runtime?

After doing some research I think the following posting is the most relevant but I'm afraid it doesn't lead me to an answer seeing as how new I am to this: Xrm.Page.data is null

My question is why does the console return this error if the element clearly exists?

Answer

Svendberg picture Svendberg · Oct 16, 2012

A handy trick when debugging a problem like this:

The Xrm.Page object lives in the context of a frame. If you want to use console in IE Developer tools without having to break in debug mode, you first have to point to the frame on the page.

Example:

frames[0].Xrm.Page.getAttribute('ati_clin').getValue()