Skip to main content

Notifications

Announcements

No record found.

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 Microsoft Employee

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Passing parameter value to fetch-based report from entity form

    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'.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Passing parameter value to fetch-based report from entity form

    Hello,

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Passing parameter value to fetch-based report from entity form

    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?

  • MehrCrm Profile Picture
    MehrCrm 290 on at
    RE: Passing parameter value to fetch-based report from entity form

    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
    Community Member Microsoft Employee on at
    RE: Passing parameter value to fetch-based report from entity form

    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
    MehrCrm 290 on at
    RE: Passing parameter value to fetch-based report from entity form

    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;
    }
    


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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,309 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans