Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

How to connect JS web-resource to HTML web-resource correctly

(0) ShareShare
ReportReport
Posted on by

Hello everyone.

I need to create html button on some form of 'contact' entity and add to it some logic. Also I need separate all my JS from html. First things first I created html web-resource with this code:

<!DOCTYPE html>
<html>
    <head>
        <script src=""></script>
    </head>
    <body>
        <button onclick="some()">Copy address</button>
    </body>
</html>
.
.
.
After it I wrote this JS with namespaces in separate web-resource:
var DA = DA || {};
DA.CRM = DA.CRM || {};
DA.CRM.Contact = DA.CRM.Contact || {};
DA.CRM.Contact.FormScripts = {
        some: function(xrmformContext){
            window.Xrm = xrm;
            window._formContext = formContext;
        
            alert("hello world");
}
.
.
.
I have two questions:
1. How I should write the path of JS web-resource for <script src=""></script>? I tried this wariants:
- <script src="defaultPublisher_myResource"></script>
- <script src="defaultPublisher_myResource.js"></script>
- <script src="myResource"></script>
- <script src="./WebResources/defaultPublisher_myResource"></script>
- <script src="./WebResources/defaultPublisher_myResource.js"></script>
All of them didn't work 
2. How I should call my method considering that it is inside namespaces? I mean in this row: <button onclick="some()">Copy address</button>. Something like this DA.CRM.Contact.FormScripts.some()? 
  • Charan Raju C R Profile Picture
    7 Moderator on at
    RE: How to connect JS web-resource to HTML web-resource correctly

    Hi EaredGen,

    Have you managed to add javascript reference in HTML webresource?

  • Suggested answer
    Charan Raju C R Profile Picture
    7 Moderator on at
    RE: How to connect JS web-resource to HTML web-resource correctly

    Hi EaredGen,

    1. Javascript webresource path reference in HTML is depends on both HTML and javascript webresource path names. This should always be a relative path, if you have maintained a folder structure while creating the webresources.

    For example, 

    If your javascript webresource name is: new_MyJSWebresource and HTML webresource name is: new_MyHTMLWebresource then, your script source in HTML should be: <script src="new_MyJSWebresource"></script>

    If your javascript webresource name is: new_MyJSWebresource.js and HTML webresource name is: new_MyHTMLWebresource then, your script source in HTML should be: <script src="new_MyJSWebresource.js"></script>

    If your javascript webresource name is: new_/Scripts/new_MyJSWebresource.js and HTML webresource name is: new_MyHTMLWebresource then, your script source in HTML should be: <script src="new_/Scripts/MyJSWebresource.js"></script>

    If your javascript webresource name is: new_/Scripts/new_MyJSWebresource.js and HTML webresource name is: new_/Webpages/MyHTMLWebresource then, your script source in HTML should be: <script src="../Scripts/MyJSWebresource.js"></script>

    2. Calling method should be a complete name including namespace. In your case, it should be: DA.CRM.Contact.FormScripts.some()

    I noticed one syntax error in your javascript code. There is a missing closing brace "}" for some: function. Fix this syntax error and try again, this could resolve your issue.

  • necsa Profile Picture
    3,455 on at
    RE: How to connect JS web-resource to HTML web-resource correctly

    Hi,

    Please get as reference following link:

    vjcity.blogspot.com/search

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,947 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans