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
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
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".
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.
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.
One more hint - try to reorder to make Moment.js to load first.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Community Member 2
UllrSki 2
SC-08081331-0 1