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

Announcements

News and Announcements icon
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()? 
I have the same question (0)
  • necsa Profile Picture
    3,455 on at

    Hi,

    Please get as reference following link:

    vjcity.blogspot.com/search

  • Suggested answer
    Charan Raju C R Profile Picture
    7 Moderator on at

    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.

  • Charan Raju C R Profile Picture
    7 Moderator on at

    Hi EaredGen,

    Have you managed to add javascript reference in HTML webresource?

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 142 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
11manish Profile Picture

11manish 119

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans