문제

Following up from my solved [previous issue][1], I'm having trouble building a simple HTML Web resource containing some basic javascript, page is rendered correctly but script doesn't seem to work properly.

My HTML resource is very basic:

<html>
<head>
    <script src="ClientGlobalContext.js.aspx" />
    <script type="text/javascript" src="new_jquery_1.7.2.min" />
    <script type="text/javascript">    

        function buttonClick() { alert('Yo !'); }

    </script>
</head>
<body>
    <input type="button" value="Test" onclick="javascript: buttonClick();" />
</body>
</html>

Although the page shows up fine, clicking the button yields The value of the property is null or undefined not a function object error like the functions wasn't there, but I checked via F12 console that the code is rendered correctly.

I also tried invoking the web resource via the direct url, in the form of

http://mycrmserver/myorg/WebResources/new_myResource

But (as I expected) the behavior of the page was the same.

I checked Google, I surfed a couple of other SO questions and MSDN and all state this is the right way to do it, what's wrong with my code ?

Other (not sure if useful) details:

  • If the F12 tool is open the error comes up as a SCRIPT5007 javascript runtime error in the console. If it's not, I get the usual script error notify popup if I browse to the webresource direct url, or nothing happens at all if I try to open the resource inside the CRM.
  • The CRM environment is updated to Rollup 3 (updating it is not an option unfortunately)
  • I'm using IE 9 (Remember: Dynamics CRM can't be used in non-IE browsers yet)


UPDATE Shorthand tags confuse the CRM.

Basically this syntax sometimes gets messed up:

<script src="ClientGlobalContext.js.aspx" />

But this works perfectly:

<script src="ClientGlobalContext.js.aspx"></script>
도움이 되었습니까?

해결책

Root cause is a missing script tag, despite the code you posted being correct.

CRM does some messing about with the HTML you post into the script editor window. What is rendered in the browser is this (note that the ClientGlobalContext.js.aspx tag is not closed in the same way as your pasted code):

<HTML><HEAD>
<SCRIPT src="ClientGlobalContext.js.aspx">
<script type="text/javascript" src="new_jquery_1.7.2.min" />
<script type="text/javascript">    

    function buttonClick() { alert('Yo !'); }

</SCRIPT>

<META charset=utf-8></HEAD>
<META charset=utf-8></HEAD>
<BODY><INPUT onclick=javascript:buttonClick(); value=Test type=button></BODY></HTML>

Resolution: Add full "close" tags to each opening script tag (rather than using "/>").

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top