web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript Web Resource referenced in HTML Web Resource - not working

(0) ShareShare
ReportReport
Posted on by

Hi all,

My ultimate goal is to be able to display a list of lookup items as a dropdown on a form.  That being said, I'm trying the approach of adding an HTML Web Resource that contains an HTML dropdown, and populating that dropdown via javascript (so that I don't get the 'Lookup Search' form, especially the 'Look for More Records' link).

So I have two web resources: An HTML web resource, that references a javascript resource.  The HTML resource loads ClientGlobalContext.js.aspx first, and this works fine.

But once it loads the custom javascript web resource, nothing in the body tag is displayed.   If I comment out the reference to the javascript file, it loads fine.  I've even paired down both web resources so that they don't do any real work, in an effort to try to get them to load.

Here is my HTML web resource:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title></title>
        <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
        <script src="../WebResources/new_lookupdrowndown.js" type="text/javascript"/>
         <link href="/_common/styles/fonts.css.aspx?lcid=1033" rel="stylesheet" type="text/css"/>  
        <link href="/_common/styles/global.css.aspx?lcid=1033" rel="stylesheet" type="text/css"/>  
        <link href="/_common/styles/select.css.aspx?lcid=1033" rel="stylesheet" type="text/css"/>  
    </head>
    <body>
	Test Page
    </body>
</html>

Here's the javascript web resource (just one of the utility functions that I'll eventually need):

function SetLookupValueToNull(fieldName) {
    if (fieldName != null) {
        window.parent.Xrm.Page.getAttribute(fieldName).setValue(null);
    }
}

I see in the Network tab of the browser dev tools that the custom javascript is loaded correctly (no 404).
I do see an error in the Console, but it's different for each browser. Here's what I see in Chrome:


Learning Path Load Script callback error: TypeError: Cannot read property 'Util' of undefined

I don't see this error when I comment out the customer javascript reference.

Any ideas what could be happening here? This could be a cross-domain issue, I guess, but I'm not sure how to handle it.
Another option would be to embed the script code in the HTML page; that feels wrong, but I've had several problems getting to this point, and I really need to get this finished.

Thanks in advance for any help.

*This post is locked for comments

I have the same question (0)
  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    Hi Philmar,

    I may be wrong but it looks like the path you have used for your js web resource is not worrect, it shouldn't have web resource, rather the name of the js. Take a look here-

    docs.microsoft.com/.../webpage-html-web-resources

    Hope this helps.

  • Community Member Profile Picture
    on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    Hi Ravi,

    Thanks for the reply.  Unfortunately, I don't think this is true for a couple of reasons:

    1) Thu URL in the edit web resource screen includes WebResources

    2) When I change it to anything else, I get a 404 in the browser Network debug tool

    Plus, I've experimented quite a lot to make sure that I don't get that 404.  When I leave WebResource in, I get a 200 OK when loading that file.

    Any other ideas?  Thanks!

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    Hi,

    Yes, the web resource will have that as the direct url but while using it in HTML web resource, you need to use the name of the web resource (as mentioned the link I shared).

    Take a look at this blog as well

    carldesouza.com/dynamics-365-add-javascript-button-html-web-resource

    Hope this helps.

  • Community Member Profile Picture
    on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    I'm just wondering why would I get a 404 when I remove 'WebResource', but not get a 404 when I leave it in?

    I'm not trying to argue.  I'm just using the tools that I have available, and they tell me that the name is correct.

    Also, when I copy the link from the Network debugger tool, I can download it.  

  • Community Member Profile Picture
    on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    Hi - does anyone have any other suggestions?

    At this point I'm embedding the javascript into the web page - which I'm not a fan of.  But I haven't been able to get this to work in any other way.

    Thanks,

    Phil

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    Hi Philmar

    I know you are not getting 404 but the fact that the js works when you embed  clearly indicates the issue is with script loading.

    I would try the following

    If you open the js webresource link from upload page and just get the file name not the resource relative path

    And in your src attribute just have the file.

    new_lookupdrowndown.js

    When web resource loaded since the html and is web resources live in the same folder it will be able load without relative path.

    Let me know if this works.

  • Community Member Profile Picture
    on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    No change in behavior, thanks for the reply.

    But do you know what did cause a change?  When I added script blocks before and after:

    <script>

    console.log('***before load');

    </script>

    <script src="new_testscript.js"/>

    <script>

    console.log('***after load');

    </script>

    When I did this, my script loads.  This is very strange. If I remove either one of these, the script doesn't run.

    I am hooking the document.ready event in my script; could this be tied to it somehow?

     

    Thanks

  • Community Member Profile Picture
    on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    So I've dug further - I don't understand this; I've tried it on 2 separate CRM instances, with the same behavior.  

    If I put an empty <script> block after each of my scripts that I'm referencing, it works.  If I omit them, it doesn't.  So this works:

    <script src="new_testscript.js"/>

    <script></script>

    Like I said, this happens on multiple CRM instances.  Any idea why?

  • Suggested answer
    WCL Profile Picture
    140 on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

    I know this is an old thread - just adding for anybody that is looking here for a solution - the issue is in

    <script src="../WebResources/new_lookupdrowndown.js" type="text/javascript"/>

    The <script> element is a content element so has to have a closing tag - it cannot be self closing

    So above needs to be

    <script src="../WebResources/new_lookupdrowndown.js" type="text/javascript"></script>

    So basically the problem was invalid xhtml ...
  • Colbreez Profile Picture
    7 on at
    RE: JavaScript Web Resource referenced in HTML Web Resource - not working

     f

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans