Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

How should I split my HTML and Javascript code?

(0) ShareShare
ReportReport
Posted on by 45

Hello

I'm working on my first custom web resource. I would like to have an HTML web resource that displays information from a FetchXML query. This web resource is inside a tab on one of my forms. Right now, I have a javascript function embedded in the html page:

    <script>
        function loadMockAssetIntoTable() {

...

Right now this function is just testing that I can execute JS inside of the HTML web resource from another Javascript file that handles the event logic:

  this.productTabLoad = function (executionContext) {
    var formContext = executionContext.getFormContext()
    var tabState = formContext.ui.tabs.get('tab_5').getDisplayState()
    if (tabState === 'expanded') {
      Xrm.Page.getControl('WebResource_ProductSelectionPage').getObject().contentWindow.loadMockAssetIntoTable()
    }

...

Now, I need to add code so I can pass data from a fetchXML query in the Javascript event handler to the HTML web resource. It looks like there are a few different approaches to do that. I'm not sure which method to use. I'm also not sure if the structure of my code is correct either. Should I move all of this logic directly into the HTML web resource?

What would be a good design choice in this workflow? I would like to limit the amount of times my fetchXML query is executed to achieve good performance. This is why I have it inside the event handler JS file.

  • rallen20 Profile Picture
    45 on at
    RE: How should I split my HTML and Javascript code?

    Hey Ravi

    Thanks for sharing those links. I still have questions regarding sending data back and forth between JS form libraries and my HTML web resources. I will need to display fetchXML data in the web resources even though the transaction will occur in the JS library. How would I handle sending large JSON strings from my library to my HTML web resource? I think I read that there is a limitation on the length of a string.

    Do you have any links about the best practices for sending JSON between JS library and HTML web resources?

    Thanks

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: How should I split my HTML and Javascript code?

    Hi,

    You can create a separate JS library with all your methods and refer that in your html. The only thing you need to ensure is you use the correct relative path while referencing in HTML.

    Refer these-

    docs.microsoft.com/.../gg309414(v=crm.8)

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/199908/issue-referencing-js-files-in-html-web-resource-page-crm-2013

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/194638/how-to-refers-to-javascript-webresource-in-html-webresource

    Hope this helps.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Dynamics 365 general forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans