Customer Engagement & Dynamics CRM Forum

 View Only
  • 1.  JS Code Spaces: Ribbon vs. Form

    Posted Apr 20, 2020 04:27 PM
    I am in the process of a rewrite/refactor of my customizations, and I'm trying to make my JS loads as efficient as possible. My question has to do with the "space" in which my JS code runs in the Ribbon vs. the Main form.

    If I load a code file with Method-X in the Ribbon, can the Main Form code files find Method-X without explicitly loaded the first code file again?


    Glen Wolinsky
    Lead Applications Developer
    Miller & Martin PLLC
    Chickamauga GA

  • 2.  RE: JS Code Spaces: Ribbon vs. Form

    Posted Apr 21, 2020 08:14 AM
    As far as I know the ribbon and the form are actually different frames, and any sort of code that would work to call function of JS in another frame would not be supported code.

    Daryl LaBar
    President, MVP
    Gap Integrity
    Fishers IN

  • 3.  RE: JS Code Spaces: Ribbon vs. Form

    Posted May 01, 2020 11:35 AM

    Thanks for your response. Over the past few days, I've been doing some experimentation with dependencies and js between the ribbon and main form. Here's what I found so far:

    1. Common js file:  Library of commonly-used routines across entire Organization
      • This file is referenced by main-form scripts and ribbon scripts

    2. Main js file:  The js code that executes from the main form.  
      • Dependencies include:
        • All non-displayed form fields that the script needs (avoids loading down form with a bunch of hidden fields)
        • The common js file

    3. Ribbon js file: The js code that excutes to show/hide and execute buttons on the ribbon.
      • NO dependencies defined.

    When loading the form in debug mode, I discovered a few things about how and where the js runs for both the ribbon and main form.  Also, the dependencies have a nuance of which you should be aware.

    1. Scripts for ribbon run in one frame and scripts for the main form do indeed run in a separate frame.
    2. The ribbon script can successfully access the Common script which is only defined as a dependency in the Main script!  Does this mean there is cross-frame scripting going on?  I don't think so.
    3. Another thing is that all of the attribute dependencies defined on the Main script are accessible by the ribbon script.
    4. It seems that the ribbon doesn't cross frame boundaries but it DOES seem to read the main form dependencies and use them. 
    5. The debug session revealed that the Common code file the ribbon was using was loaded into the Ribbon frame and was NOT being run from the Main form frame.
    6. NOTE:  Trying to define attribute dependencies for the RIBBON script does not work!  It seems you HAVE TO define any dependencies for the Ribbon to use by defining them in a script dependency on the main form or by actually including the field as hidden on the main form.

    ANYONE: Please let me know if I'm on base here or horribly wrong.  I want to get a handle on this as I am refactoring our system and want to keep my JS code files trim and organized. 

    Glen Wolinsky

    Glen Wolinsky
    Lead Applications Developer
    Miller & Martin PLLC
    Chickamauga GA

  • 4.  RE: JS Code Spaces: Ribbon vs. Form

    Posted Jun 15, 2020 05:51 PM

    Hi Glen

    I have created a project that addresses all of these "headaches" so you don't have to. It uses the power of module bundling to bundle all of your code so you only have to deal with one file when you upload it to your d365 system while maintaining good code structure.

    Please let me know if you have any questions.

    Rex Kenley Tan, MCSA, MCSD
    Minneapolis MN

    *Always be CURRENT with JavaScript & C#, NEVER be obsolete.

    DISCLAIMER: All views expressed on this site are my own and DO NOT represent the opinions of ANY entity whatsoever with which I have been, am now, or will be affiliated.

If you've found this thread useful, dive deeper into User Group community content by role