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

Notifications

Announcements

No record found.

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)
  • Community Member Profile Picture
    on at

    I guess you open web resource using Xrm.Page.openDialog(). In this case i suggest you passing your json as GET parameters to your web resource url. For example

    var myJson = JSON.stringify(myData);
    
    Xrm.Page.openDialog(url.myresource.html?data=myJson);



    And then parse that data parameter in your web resource

  • Jayakumar Profile Picture
    390 on at

    Hi Agust,

    Thanks for reply. I am not opening dialog. There is web resource section in the crm form. I am setting the web resource url in the crm form using setsrc dynamically. How to pass using this method.

  • Verified answer
    Community Member Profile Picture
    on at

    Even with setSrc you are going to do the same thing that I told you before. Also for reference take a look at this:msdn.microsoft.com/.../gg327945.aspx

  • Jayakumar Profile Picture
    390 on at

    Hi Agust,

    I was able to pass the data as query string successfully. But now the problem is there is a limit for query string. I am not getting the full data in query string due to limit of string length. Is there any way to post the form data to a webresource or accessing the json object in parent form from the web resource.

    Thanks.

  • Community Member Profile Picture
    on at

    Please can you mark my answer as correct. As about your other problem you can access a variable from your web resource using window.parent.document e.g:

    Suppose in your main javascript file(the file you upload to the entity form)  you have your global variable where you store your object:

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

     

    Now to access this variable from your web resource you type:

    var myVariableInWebResource = window.parent.document.myVariable;


    And now you can use your data inside your web resource

     

  • Jayakumar Profile Picture
    390 on at

    Hi Agust,

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

  • Jayakumar Profile Picture
    390 on at

    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.

  • Suggested answer
    MehrCrm Profile Picture
    290 on at

    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

  • Community Member Profile Picture
    on at

    Sorry my mistake. Access it:

    var myVariableInWebResource = window.parent.myVariable;

    Remove document.

  • Jayakumar Profile Picture
    390 on at

    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.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans