javascript - "Object doesn't support property or method 'getAttribute'" - Stack Overfl

admin2025-04-19  0

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 plains 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?

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 plains 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?

Share edited May 23, 2017 at 12:27 CommunityBot 11 silver badge asked Oct 15, 2012 at 18:31 Chris76786777Chris76786777 7391 gold badge13 silver badges24 bronze badges 7
  • So this is happening in code registered to the OnLoad event of the OrderDetail form? – Peter Majeed Commented Oct 15, 2012 at 22:27
  • The code that I'm running, I'm doing from the console after the whole page has loaded. The code that I intend to run is registered to run at OnLoad. – Chris76786777 Commented Oct 15, 2012 at 22:45
  • 1 You'll find that this is the case generally throughout the CRM. Try running your code in any entity and you'll find similar behavior. However, if you put a breakpoint in your code and debug, you should see the correct behavior in the console during break mode. While in break mode, which line in particular breaks? – Peter Majeed Commented Oct 15, 2012 at 23:15
  • I took your suggestion and discovered two things: (1) I was focusing on the wrong line (the debugging helped me to see it was a line further down that was failing and not the one I initially thought) and (2) that I was using the wrong entity name. I was using "order" instead of "salesorder". – Chris76786777 Commented Oct 16, 2012 at 0:49
  • 3 The Xrm.Page object lives in the context of a frame. If you want to use console in IE Dev 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() – Svendberg Commented Oct 16, 2012 at 6:57
 |  Show 2 more ments

1 Answer 1

Reset to default 3

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()
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745057999a282520.html

最新回复(0)