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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Including an external js file inside a js web resource

(0) ShareShare
ReportReport
Posted on by

Hi,

Basically I want create a javascript file which contains some public functions and can be shared by my different javascript web resource. The problem is that js file is not like html file that you can have include file where you can refer an external javascript file. For example, I create a js file called myPublicJsLib.js and I want my other javascript web resource can use the functions defined in myPublicJsLib.js. How I can do this?

Thanks,

Lan

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    As it relates to CRM, you would link your myPublicJsLib.js webresource to the form and put it before (move up to the top) any other JavaScript webresource that referenced it on the same form.


    If I've misunderstood, and you instead need to download the webresource in code then you could use this function

        this.DownloadWebResource = function (webResourceName, isSynchronousCall, callBackFunction) {
            webResourceName = "../WebResources/" + webResourceName;
            if (typeof ($) == "undefined")
                throw "jquery is required to use the DownloadWebResource function";
            else {
                $.ajax({
                    url: webResourceName,
                    async: !isSynchronousCall,
                    success: function (data) {
                        if (isSynchronousCall)
                            return data;
                        else
                            callBackFunction(data);
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        throw errorThrown;
                    }
                });
            }
        }


  • Community Member Profile Picture
    on at

    Hi,

    So you mean I have to add this public JS file in each form which contains the JS web resources need to refer the public JS?

    Thanks,

    Lan

  • Community Member Profile Picture
    on at

    Hi,

    Yes, you are right, once I add this public JS file on the form, then I can refer the js function in the public JS file. But again, I am wondering if I can bypass this so I don't have to add this public JS file on each form.

    Thanks,

    Lan

  • Verified answer
    Community Member Profile Picture
    on at

    If you want to bypass then use the function I provided in my first response.  Just make sure you run that function first before any other function.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans