Skip to main content

Dynamics Set IFrame URL - D365 v8 vs. D365 v9

While doing client work, I came across a problem with setting an IFrame URL dynamically.  The underlying issue was that the sandbox instance is on v8 of Dynamics 365 and production is on v9 of Dynamics 365.  The reason for this was because this client was setup around the time that Microsoft rolled out v9.  Anyways, JavaScript that I wrote to dynamically set the URL of the IFrame wasn't working in the v9 instance.  This was because of changes that Microsoft made to how IFrames are loaded on the form and also changes to JavaScript.

Here is my v8 setup:
  1. JavaScript runs OnLoad of contact form.  This works because of how IFrames are loaded in v8.  You can also run it on either a tab change (hide / show) or OnReadyStateComplete event of the IFrame.  Depending on your setup you will need to choose which is best for you.  For me in this case it was the OnLoad event.
  2. Here is the JavaScript:
 function OnLoad()  
 {  
      //Get memberid  
      var value = Xrm.Page.data.entity.attributes.get("new_memberid").getValue();  
      //Get the default URL for the IFRAME, which includes the   
      // query string parameters  
      var IFrame = Xrm.Page.ui.controls.get("IFRAME_NAMEofIFRAME");  
      var Url = IFrame.getSrc();  
      //Append the parameters to the new page URL  
      newTarget = Url + "history?member=" + value;  
      // Use the setSrc method so that the IFRAME uses the  
      // new page with the existing parameters  
      IFrame.setSrc(newTarget);  
 }  

Here is my v9 setup:
  1. JavaScript runs on OnReadyStateComplete event of the IFrame.  I had to add extra code to prevent constant refresh of the IFrame.  This is because on this event every time we update the URL if causes the OnReadyStateComplete event to fire.  To prevent this we have to use an If/Else so we only update the URL if it hasn't been updated yet.
  2. Here is the JavaScript:
 function OnReadyStateComplete(executionContext)  
 {  
      var formContext = executionContext.getFormContext();  
      var value = formContext.getAttribute("new_memberid").getValue();  
      //Get the default URL for the IFRAME, which includes the   
      // query string parameters  
      var IFrame = formContext.ui.controls.get("IFRAME_NAMEofIFRAME");  
      var Url = IFrame.getSrc();  
      var newTarget = "";  
      //Append the parameters to the new page URL  
      if(Url.includes(value))  
      {  
           newTarget = Url;  
      }  
      else  
      {  
           newTarget = Url + "history?member=" + value;  
           // Use the setSrc method so that the IFRAME uses the  
           // new page with the existing parameters  
           IFrame.setSrc(newTarget);  
      }  
 }  

As you can see in my v9 code I have to pass in the execution context so I can create the form context.  To do that you have to check the box next to, "Pass execution context as first parameter" when adding the JavaScript to the form.


Microsoft has not yet deprecated Xrm.Page yet but it is coming, so it is best to plan for it.  Here are some important links I used when solving my problem of the JavaScript not running:

Important Change (deprecations) coming
OnReadyStateComplete
Execution Context
Form Context
Walkthrough: Write your first client script
Client API Reference

Comments

  1. There are a few apparatuses where you can get even data on inbound connections and outbound connections, yet in this article we will concentrate on Spam Score. access the darknet

    ReplyDelete
  2. Seattle Software Developers : This blog consistently delivers valuable information that's hard to find elsewhere. The articles are well-researched and cover a wide range of topics. Highly recommended!

    ReplyDelete
  3. Establish clear rules and guidelines for your server and appoint responsible moderators to ensure a safe and welcoming environment.

    discord online member kaufen

    ReplyDelete
  4. The ethics surrounding buying Discord members can be a contentious topic. Critics argue that artificially inflating member counts can lead to inauthentic interactions, potentially undermining the integrity of the community. However, proponents contend that it can act as a catalyst, attracting genuine members who join after observing a thriving community.

    discord online member kaufen

    ReplyDelete
  5. TikTok has become a global sensation, capturing the attention of millions with its engaging short videos and rapidly growing user base. With the promise of fame and fortune, the competition to stand out on the platform is fierce. In this quest for popularity, a controversial trend has emerged: "TikTok Live Zuschauer Kaufen," which translates to buying live viewers on TikTok. In this article, we will delve into this contentious practice, exploring its motivations, potential consequences, and ethical considerations.

    tiktok live zuschauer kaufen

    ReplyDelete
  6. Karaoke has been a beloved pastime for music enthusiasts around the world. With karaoke backing tracks, aspiring singers can take their performances to the next level. These tracks often include lyrics and background vocals, allowing singers to feel like they're performing with a live band. It's the perfect way to showcase your vocal skills and have a blast at the same time.


    karaoke backing tracks

    ReplyDelete
  7. Ecological Surveys
    For projects that may affect local ecosystems, ecological surveys are conducted to assess the impact and develop mitigation strategies. This includes studying flora, fauna, and habitat dynamics.

    phase 1 desk study report

    ReplyDelete
  8. What does the future hold for the English wine industry? Delve into emerging trends and projections for the growth and development of English wines.

    English Red Wine

    ReplyDelete
  9. The UAE's multicultural society has a profound influence on interior design. It encourages a fusion of design styles, resulting in eclectic and vibrant spaces that resonate with a global audience.


    interior design companies in business bay

    ReplyDelete
  10. Slot88 and Slot Maxwin boast an extensive selection of themed slot games, from ancient civilizations to modern pop culture. This variety ensures that players always have something new and exciting to explore. Megajudi303's dedication to responsible gaming is reflected in their self-exclusion and deposit limit options, which allow players to set boundaries and play within their means.

    Slot maxwin

    ReplyDelete
  11. Full-screen timers have revolutionized the way we manage time and maintain focus in an era filled with distractions. Their immersive nature and visual countdowns make them powerful tools for staying on track and accomplishing tasks efficiently.

    fullscreen timer

    ReplyDelete

Post a Comment

Popular posts from this blog

Validating User Input In CRM Portals With JavaScript

When we are setting up CRM Portals to allow customers to update their information, open cases, fill out an applications, etc. We want to make sure that we are validating their input before it is committed to CRM.  This way we ensure that our data is clean and meaningful to us and the customer. CRM Portals already has a lot validation checks built into it. But, on occasion we need to add our own.  To do this we will use JavaScript to run the validation and also to output a message to the user to tell them there is an issue they need to fix. Before we can do any JavaScript, we need to check and see if we are using JavaScript on an Entity Form or Web Page.  This is because the JavaScript, while similar, will be different.  First, we will go over the JavaScript for Entity Forms.  Then, we will go over the JavaScript for Web Pages.  Finally, we will look at the notification JavaScript. Entity Form: if (window.jQuery) { (function ($) { if (typeof (entityFormClientVali

SCRIBE Software Acquired By TIBCO

On June 6th, 2018 Scribe Software was acquired by TIBCO.  Below is the announcement I and other partners received in an e-mail with links to the press release. "We are pleased to announce that on June 6, Scribe Software was acquired by TIBCO Software. This milestone reflects the increasing strategic importance that Scribe’s product line has with IT organizations and presents great opportunities for Scribe’s partner community. In the short term, there will be no immediate impact to how you conduct business with Scribe. Your sales and support contacts will all remain the same. Over time, we expect that the combination of Scribe’s best-in-class iPaaS with TIBCO’s enterprise product portfolio, which includes messaging, application integration, API management, and analytics offerings, will provide significant capabilities and opportunities for Scribe’s partner community. To learn more about the opportunities that lay ahead, read the  press release ..."