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)

Reference JS library/function in another JS library with Chrome or Firefox

(0) ShareShare
ReportReport
Posted on by 410

Hi,

I am having problems referencing another JS library/function within another. I actually was able to do this in IE via this code:

------------

LoadWebResource = function(resourceName) { 
      var httpRequest = new ActiveXObject("Msxml2.XMLHTTP");  //not supported by Chrome or Firefox!
      httpRequest.open("GET", Xrm.Page.context.getClientUrl() + "/webresources/" + resourceName, false);
      httpRequest.send(null); 
      try { eval(httpRequest.responseText); } 
      catch (e) {  alert("Error loading " + resourceName + ":\n" + e.description); } 
 }

LoadWebResource("mag_/js/alert.js");

------------

The problem is that ActiveXObject is only supported by IE, not chrome or firefox.

Is there a similar method that works in all browsers?




 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Reference JS library/function in another JS library with Chrome or Firefox

    Hello,

    Just curious - why do you want to use such approach instead of direct referencing of webresource?

    If you want to do that anyway check this thread - stackoverflow.com/.../dynamically-load-js-inside-js

  • f23fzf34ffavcz2t56 Profile Picture
    221 on at
    RE: Reference JS library/function in another JS library with Chrome or Firefox

    How do you do "direct referencing of webresource"? I'm trying to do some date manipulations so I included momentjs as a web resource but when I try to use it in my own script CRM says "moment is not defined".

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Reference JS library/function in another JS library with Chrome or Firefox

    Let's assume that you work on some form script and you need to add moment.js there.

    Just open Form you are develop JS for, click "Form Properties" button, in "Form Libraries" section click Add and add a reference to moment.js webresource. After that you will be able to use it inside code of your webresource.

    If something is not clear you can check this thread that contains step-by-step instructions.

  • f23fzf34ffavcz2t56 Profile Picture
    221 on at
    RE: Reference JS library/function in another JS library with Chrome or Firefox

    Yeah, that's what I did. I expected it to work but it's not. It's really late here so maybe I need to look at this again tomorrow to find my mistake. Thanks.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Reference JS library/function in another JS library with Chrome or Firefox

    One more hint - try to reorder to make Moment.js to load first.

  • HodgesW Profile Picture
    410 on at
    RE: Reference JS library/function in another JS library with Chrome or Firefox

    The order of the libraries actually did not matter for me and just loading all my Libraries on the form worked! The only downside is that then now I have three custom (my custom, online developed Alert.js library, custom jquery library) libraries that need to load whenever the form loads -- rather than loading the last two libraries when the specific function is called (only used when user clicks "mark complete").

    Turns out I didn't fully understand my error and hadn't tried all the combinations. Having the double library reference confused me a bit. 

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
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans