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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Passing JSON object to HTML Web resource

(0) ShareShare
ReportReport
Posted on by 390

Hi,

How to pass json object to web resource. We are calling web api on form load and displaying the data in the form. Some values we get from api need to be displayed in the html web resource. How to pass JSON data to web resource. I know I can call the same api in the web resource. But we don't want that because I have more than 5 web resources where we want to show the data. I cannot call the api on each web resource. I just want to call on load and load the data in crm form and web resources.

Thnaks

*This post is locked for comments

I have the same question (0)
  • Besiana  Profile Picture
    5 on at
    RE: Passing JSON object to HTML Web resource

    Great! Thank's Agust!!

  • Jayakumar Profile Picture
    390 on at
    RE: Passing JSON object to HTML Web resource

    Thanks for the Information.

  • Community Member Profile Picture
    on at
    RE: Passing JSON object to HTML Web resource

    Sorry i have been busy.

    Another way is using localStorage. Supported by all browsers and is safe, of course only if you dont have a lot of sensitive data. Permits storing large size of data. You can read about it here http://www.w3schools.com/html/html5_webstorage.asp.

    So in your case you can do it.

    var myVariableInDynamicsForm = {key : value};
    localStorage.setItem("myVariable", JSON.stringify(myVariableInDynamicsForm));
    
    
    
    var myVariableInWebresource = JSON.parse(localStorage.getItem("myVariable"));


  • Jayakumar Profile Picture
    390 on at
    RE: Passing JSON object to HTML Web resource

    Hi,

    Anyone please answer how to access parent variable from iframe web resource in crm 2016 using turbo form. When I switched back to Legacy mode I can access the parent variable using code below.

    legacy.png

    window.parent.myVariable

    So the problem is due to turbo form. So is there no way to access the parent variable from iframe using turbo form?

  • Jayakumar Profile Picture
    390 on at
    RE: Passing JSON object to HTML Web resource

    Hi MehrCrm,

    window.parent.myVariable gives undefined error. It works in MS CRM 2011 but not in 2016. Is it because due to introduction of turbo forms in CRM 2016??

    Thanks,

  • Jayakumar Profile Picture
    390 on at
    RE: Passing JSON object to HTML Web resource

    This does not work in MS CRM 2016. But it works in crm 2011. I can acces the variable in parent script in iframe in crm 2011. But when I use the same code in crm 2016 I am getting undefined error.

  • Community Member Profile Picture
    on at
    RE: Passing JSON object to HTML Web resource

    Sorry my mistake. Access it:

    var myVariableInWebResource = window.parent.myVariable;

    Remove document.

  • Suggested answer
    MehrCrm Profile Picture
    290 on at
    RE: Passing JSON object to HTML Web resource

    Please add (or use existing) form onload handler in your JS web resource where the global variable is defined.

    var myVariable = {"key" : "value"};

    function FormOnloadHandler(context) {

    // This resource is being loaded as an iframe

    // Add a new variable with the same name to the parent of this iframe, main form window

    // Assign your local variable to the main form window which then becomes accessible from any web resource on the form

        window.parent.myVariable = myVariable;

    }

    In your web resource, access the variable:

    if (window.parent.myVariable) {

        // window.parent.myVariable

    }

    Hope this helps

  • Jayakumar Profile Picture
    390 on at
    RE: Passing JSON object to HTML Web resource

    Hi Agust,

    No. I cannot access the variable which is in the CRM main from form the IFrame Web resource. We can access the parent form fields but not the variable. The variable is declared as global.

    Thanks.

  • Jayakumar Profile Picture
    390 on at
    RE: Passing JSON object to HTML Web resource

    Hi Agust,

    I will try this and update you. Thanks for your help.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans