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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Passing parameter value to fetch-based report from entity form

(0) ShareShare
ReportReport
Posted on by

Here's what I'm trying to do: When I go to a company form, I want the company guid of that company to be passed automatically to a fetch-based report that's embedded on the company form with an iframe.

Right now, I have successfully written the fetch-based report I want. I can run it outside of the company form and input a company guid -- that works. I can run it within the company form through the iframe, but without the results being specific to the currently-viewed company -- that works. What I can't do (and what I'm trying to figure out) is how to make the report automatically pull the GUID from the company form and run the report on it, and show those results in the iframe. What can I do?

Thanks for your help!

*This post is locked for comments

I have the same question (0)
  • MehrCrm Profile Picture
    290 on at

    You can

    1) use the following in your iframe code to get the company record guid:

    var companyGuid = window.parent.Xrm.Page.data.entity.getId();

    2) in the iframe's "Web Resource Properties" dialog (form editor), check the "Pass record object-type code and unique identifier as parameters" check box. Then in your iframe code use a function like the following to get the guid of the company record:

    function GetCompanyGuidFromParameters() {
    	var guid = null;
    
    	try {
    		if (location.search != "") {
    			var vals = location.search.substr(1).split("&");
    			// vals = ["orglcid=1033", "orgname=Demo", "userlcid=1033", "type=10016", "typename=new_company", "id={B304F88F-BFD9-E511-80C4-08002738AA19}"]
    			for (var i = 0; i < vals.length; i++) {
    				var tmp = vals[i].split("=");
    				if (tmp[0].toLowerCase() == "id" && tmp[1] != "") {
    					guid = decodeURIComponent(tmp[1]);
    					break;
    				}
    			}
    		}
    	} catch (e) {
    		console.error("Unable to retrieve Guid of the company from data parameter.\r\n" + e.message);
    	}
    	return guid;
    }
    


  • Community Member Profile Picture
    on at

    Thanks for the reply, MehrCRM. What exactly do you mean by "iframe code"? Do you mean the fetchXML? I tried assigning the GUID value as you suggested like so:

    <QueryParameter Name="@guid">
         <Value>=window.parent.Xrm.Page.data.entity.getId()</Value>
    </QueryParameter>


     I don't have a problem getting the GUID on the company page -- I can do this in the JavaScript on the page:

    var guid = Xrm.Page.data.entity.getId();


     The problem for me is passing that value into the report in the iframe, then making the report run automatically (without me having to click 'view report' to start).

  • MehrCrm Profile Picture
    290 on at

    Sorry, I misunderstood the question. Please see the following article written for 2011 but with two additional changes, it works for 2013 and up:

    mscrmshop.blogspot.ca/.../step-by-step-tutorial-to-add-crm-report.html

    1. developer should Uncheck Restrict cross-frame scripting on IFrame Propertiy

    2. When building the URL in script (SetSrc) it should be Full URL, include servername and organization name.

    After making this changes on the previous scope, the will run in embedded form

  • Community Member Profile Picture
    on at

    Okay, I followed those directions. That gives me pretty much exactly what I had successfully before -- the report shows the records from ALL the companies, not just the one I'm viewing.

    Also, in regards to #2, that makes the report error out. The report works when I follow the directions in the article "/crmreports/viewer/viewer.aspx?...", but, again, it shows the records from all companies.

    Any other suggestions on how to run the report on just the company it's on the form of?

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    This should be helpful - andreaswijayablog.blogspot.com/.../crm-2011-embed-report-in-iframe-and.html

  • Verified answer
    Community Member Profile Picture
    on at

    I figured it out!

    rajeevpentyala.com/.../pass-parameters

    ^That post has the answer. All you have to do is add the parameter name prefaced by "&p:" to the iframe source (report) URL. That's it! The input box now auto-populates and runs automatically on page load.

    More details:

    The javascript On_load function now looks like this:

    function showSuccessReport()
    {
       //Get iframe
       var iframeObject = Xrm.Page.getControl("IFRAME_Success");
    
       if (iframeObject != null) {
          var strURL = "/crmreports/viewer/viewer.aspx?action=run&context=records"
             + "&id=%7bA2449FD3-4054-E611-9417-00155D011101%7d"
             + "&records="
             + Xrm.Page.data.entity.getId()
             + "&recordstype=1&p:CompanyID="
             + Xrm.Page.data.entity.getId();
     
          //Set URL of iframe
          iframeObject.setSrc(strURL);
       }
    }
    


    'CompanyID' is the parameter name in my report. The source of the iFrame itself is set to 'about:blank'.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans