function loadIFrame() {
window.fetchActivtities = new FetchViewer("IFRAME_TEST");
fetchActivtities.FetchXml = getFetchXml();
fetchActivtities.LayoutXml = getLayoutXml();
fetchActivtities.Entity = "activitypointer";
fetchActivtities.QueryId = "{00000000-0000-0000-00aa-000010001899}"; // view GUID
fetchActivtities.RegisterOnTab(2); //IFRAME TAB INDEX
}
function getFetchXml() {
// FetchXML Query
return ' <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">' +
'<entity name="activitypointer">' +
' <attribute name="subject" />' +
' <attribute name="scheduledstart" />' +
' <attribute name="regardingobjectid" />' +
' <attribute name="prioritycode" />' +
' <attribute name="scheduledend" />' +
' <attribute name="activitytypecode" />' +
' <attribute name="instancetypecode" />' +
' <order attribute="scheduledend" descending="false" />' +
'<filter type="and">'+
'<condition attribute="regardingobjectid" operator="in">'+
'<value uitype="account">{7CC58DF6-3114-E111-8E22-1CC1DEEAE7D7}</value>'+
' </condition>'+
'</filter>'+
' <attribute name="activityid" />' +
' </entity>' +
' </fetch>';
}
function getLayoutXml() {
// grid layout, you can get easily from Customization.xml file
return '<grid name="resultset" object="4200" jump="subject" select="1" icon="1" preview="1">' +
' <row name="result" id="activityid" multiobjectidfield="activitytypecode">' +
' <cell name="instancetypecode" width="100" ishidden="1" />' +
' </row>' +
' </grid>';
}
function FetchViewer(iframeId) {
var Instance = this;
var vDynamicForm;
var m_iframeTab;
var m_iframeDoc;
Instance.Entity = "";
Instance.Iframe = null;
Instance.FetchXml = "";
Instance.QueryId = "";
Instance.LayoutXml = "";
Instance.RegisterOnTab = function (tabIndex) {
Instance.Iframe = document.getElementById(iframeId);
if (!Instance.Iframe)
return alert("Iframe " + iframeId + " is undefined");
m_iframeDoc = getIframeDocument();
var loadingGifHTML = "<table height='100%' width='100%' style='cursor:wait'>";
loadingGifHTML += "<tr>";
loadingGifHTML += "<td valign='middle' align='center'>";
loadingGifHTML += "<img alt='' src='/_imgs/AdvFind/progress.gif'/>";
loadingGifHTML += "<div/><b>Loading View...</b>";
loadingGifHTML += "</td></tr></table>";
m_iframeDoc.body.innerHTML = loadingGifHTML;
Instance.Refresh();
}
function RefreshOnReadyStateChange() {
if (Instance.Iframe.readyState != 'complete')
return;
Instance.Refresh();
}
Instance.Refresh = function () {
if (!Instance.Iframe)
return alert("Iframe " + iframeId + " is undefined");
m_iframeDoc = getIframeDocument();
Instance.Iframe.detachEvent("onreadystatechange", RefreshOnReadyStateChange);
var create = m_iframeDoc.createElement;
var append1 = m_iframeDoc.appendChild;
vDynamicForm = create("<FORM name='vDynamicForm' method='post'>");
var append2 = vDynamicForm.appendChild;
append2(create("<INPUT type='hidden' name='FetchXml'>"));
append2(create("<INPUT type='hidden' name='LayoutXml'>"));
append2(create("<INPUT type='hidden' name='EntityName'>"));
append2(create("<INPUT type='hidden' name='DefaultAdvFindViewId'>"));
append2(create("<INPUT type='hidden' name='ViewType'>"));
append1(vDynamicForm);
vDynamicForm.action = prependOrgName("/AdvancedFind/fetchData.aspx");
vDynamicForm.FetchXml.value = Instance.FetchXml;
vDynamicForm.LayoutXml.value = Instance.LayoutXml;
vDynamicForm.EntityName.value = Instance.Entity;
vDynamicForm.DefaultAdvFindViewId.value = Instance.QueryId;
vDynamicForm.ViewType.value = 1039;
vDynamicForm.submit();
Instance.Iframe.attachEvent("onreadystatechange", OnViewReady);
}
function OnViewReady() {
if (Instance.Iframe.readyState != 'complete') return;
Instance.Iframe.style.border = 0;
Instance.Iframe.detachEvent("onreadystatechange", OnViewReady);
m_iframeDoc = getIframeDocument();
m_iframeDoc.body.scroll = "no";
m_iframeDoc.body.style.padding = "0px";
}
function getIframeDocument() {
return Instance.Iframe.contentWindow.document;
}
}
Hello,
ReplyDeletethis is great post. It worked perfectly.
The only issue I have is that ribbon does not change.
I would like to get ribbon working and have charts available too.
This seems to me is possible only in subgrid control.
Do you have solution for us to share ?
Thanks Jiri
Hi, did you stumble uppon any solution yet? I have the same problem
DeleteHi Jiri,
ReplyDeleteThanks for your response. Ribbon does not change using this approach. I did not find any solution regarding this issue. you can use subgrid to change ribbon.
Hello,
ReplyDeleteWith the above code is the on_click event got fired. I need to open the Contact Form etc when the row in the grid get clicked. Any help ? In my case when I click nothing happens.
Furqan
Hi Ali,
ReplyDeleteHere we are displaying adv find view in an Iframe. OOB Adv find view funtions will work. lookup fileds will open records on click.
can you please provide me more information about your issue, I am not clear it. i can try to help you.
Hello Guru,
ReplyDeleteThe Code works perfectly. The only issue is I am facing is I am unable to open the Record when the user clicks on the Grid Row. Unable to open the entity record when the user clicks or double clicks on the record.
regards
Jayakumar Janakiraman
Hi Guru,
ReplyDeleteUnable to open the entity record when the user clicks on the grid row.
let me know if you have the solution for this.
regards
Jayakumar Janakiraman
Hi Jay,
ReplyDeleteIt seems grid does not have required fields in the layout to open the records. As mentioned in the above example instancetypecode(hidden field in the grid) & activityid(primary key) must be included in the fetchXML and also in the Grid Layout.
Try adding these field. Hope it will resolves the issue. I would suggest get the fetchXML from Adv.find and modify accordingly.
Thanks,
Guru
thanks Guru this saved my day
ReplyDeleteMany users are reporting an XSS security error pop-up. It seems the only fix is to change a machine's local security settings (add CRM to trusted sites, set trusted sites to low security, etc). Is this normal?
ReplyDeleteI'm not sure the exact issue. But adding CRM site to Trusted sites resolves most of the issues.
ReplyDeleteHow do we determine the GUID for the QueryID?
ReplyDeleteOpen any view in customization mode and then use ctr + N , it opens view in new window and you can get the ID of the view.
Deleteother way is using Data base to find the view GUID.
Hi Guru Prasad - This is a great post, albeit too advanced for me at this time. I am new to Visual Studio and the BIDS environment and I have a question regarding fetch xml, ssrs, and multiple entities to create a custom chart in CRM. Basically I want to create a chart to track trends through entities. I'd like one chart to display 4 trend lines for number of leads,opportunities,orders and invoices created per month. Is this possible?
ReplyDeleteI think you can use SSRS for your requirement.
DeleteIf I'm going to print preview funcionality, I get in error page on the print preview page. Can you suggest me something to solve this problem?
ReplyDeleteWhat kind of error are you facing?
DeleteHi
ReplyDeleteThanks for the code
I have 2 questions:
1. Can I rename the column names of the grid by some attribute of "cell" node in LayoutXml?
2. Does the aditional functionality shown on the second part of Adi's article - auto refreshing the grid after adding a record - fits CRM2011?
here is a link to the second article:
http://mscrm4ever.blogspot.co.il/2009/03/display-fetch-in-iframe-part-2.html
Thanks in advance
Tikva
I think you can rename Column names of the grid using "alias" property. tried long back, did not remembered.
DeleteHello, thanks by your post.
ReplyDeleteI'm getting an error in the line create(""). The error is "Invalid calling object". It was working an other environment, but in my new environment with update rollup 12 I'm getting the error.
Do you know which could be the reason for this?
Thank you!
Hi Serigo,
DeleteThis script is completely unsupported one. I think with recent rollup 12 it might break. I did not tried it. check the advance find layout xml, i think it might changed.
Thanks,
Guru
Hi Gure,
ReplyDeleteI took this post and created my iFrame with advanced find view. Now we updated CRM with latest update roll-up 12. The code stopped working on chrome, is there any code changes that you have for the same to work on chrome also.
Hi Rose,
DeleteSorry, I did not tested this functionality recently after roll-up 12 update.
Thanks,
Guru
This is stopped working after UR12 service update. Getting 404 error after the Post. Any idea?
ReplyDeleteSorry, I did not tested this functionality after roll-up 12 release. I tried this long back. this is completely unsupported script. i think its broken now. MS might changed the Advance find grid layout.
Deletedo we have updates on this? same issue when we installed RU 12.
ReplyDeleteHi Benjo,
DeleteThis functionality is completely unsupported and after RU 12,its stopped working. You can't display Adv. Find views in IFrame. I tried updating this solution after RU 12, I'm able to display only System/custom view's in an IFrame using this approach. Personal view's not supporting.
Thanks,
Guru
Hi Guru, having the same problem on RU 12. Hope you can give us insights on how to solve this issue soon. thanks in advance..
ReplyDeleteany updates on this? for RU 12..
ReplyDeleteAs i mentioned earlier, i made some changes to the above code after UR 12. i was successful in displaying system and custom view's in Iframe. But i was not able to display Personal view's/Adv.find view's in Iframe.
DeleteI thought there is no use of displaying system/custom view's in Iframe, we could use sub-grid in place.
Let me know what was your exact requirement? Thanks!
Guru,
Deletecan you share with me the code that you modified after ur 12. I would like to show a system/custom view in an iframe. No need for personal view.
Hi Ali,
DeleteI have updated script available on this post http://guruprasadcrm.blogspot.in/2013/07/displaying-view-in-iframe-crm-2011.html
Hi Guru, I used this code to display records in an IFrame and the IFrame resides inside a HTML page. I have a requirement to export these records into an excel file like we do in an advanced find.
ReplyDeleteIs it possible? Any approach?
you can try creating excel from FetchXML retrieved records. you can use file steam object or similar ones to create the file.
DeleteHi Guru,
ReplyDeleteThe code worked perfectly fine in ie8 with Windows xp...But it is throwing the following error in Windows 7-ie9.And the iframe is not loading.
Can u suggest me the code changes regaring this..
Microsoft Dynamics CRM Error Report Contents
1.0
Invalid calling object
120
/%7B635061225790003236%7D/WebResources/new_notesview
/userdefined/edit.aspx?_gridType=10000&etc=10000&id=%7bA6E626BD-5FCC-E211-A808-000C29C0A300%7d&pagemode=iframe&preloadcache=1370526470848&rskey=24864390
anonymous(){if(!Instance.Iframe){returnalert("Iframe"+iframeId+"isundefined");}m_iframeDoc=getIframeDocument();Instance.Iframe.detachEvent("onreadystatechange",RefreshOnReadyStateChange);varcreate=m_iframeDoc.createElement;varappend1=m_iframeDoc.appendChi
anonymous(){if(!Instance.Iframe){returnalert("Iframe"+iframeId+"isundefined");}m_iframeDoc=getIframeDocument();Instance.Iframe.detachEvent("onreadystatechange",RefreshOnReadyStateChange);varcreate=m_iframeDoc.createElement;varappend1=m_iframeDoc.appendChild;vDynamicForm=create("");varappend2=vDynamicForm.appendChild;append2(create(""));append2(create(""));append2(create(""));append2(create(""));append2(create(""));append1(vDynamicForm);vDynamicForm.action="/"+ORG_UNIQUE_NAME+"/AdvancedFind/fetchData.aspx";vDynamicForm.FetchXml.value=Instance.FetchXml;vDynamicForm.LayoutXml.value=Instance.LayoutXml;vDynamicForm.EntityName.value=Instance.Entity;vDynamicForm.DefaultAdvFindViewId.value=Instance.QueryId;vDynamicForm.ViewType.value=1039;vDynamicForm.submit();Instance.Iframe.attachEvent("onreadystatechange",OnViewReady);}
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; BRI/2)
en-us
en-in
en-in
1366x768
Web
2013-06-06T19:17:52
1033
1033
1033
1033
{02ED47A7-4BB2-E211-BB98-000C29C0A300}
{E7DE6DE9-EAB7-E211-A699-000C29C0A300}
5.0.9690.3236
Hi Guru,
ReplyDeleteThe code worked perfectly fine in ie8 with Windows xp...But it is throwing the following error in Windows 7-ie9.And the iframe is not loading.
Can u suggest me the code changes regaring this..
Microsoft Dynamics CRM Error Report Contents
1.0
Invalid calling object
120
/%7B635061225790003236%7D/WebResources/new_notesview
/userdefined/edit.aspx?_gridType=10000&etc=10000&id=%7bA6E626BD-5FCC-E211-A808-000C29C0A300%7d&pagemode=iframe&preloadcache=1370526470848&rskey=24864390
anonymous(){if(!Instance.Iframe){returnalert("Iframe"+iframeId+"isundefined");}m_iframeDoc=getIframeDocument();Instance.Iframe.detachEvent("onreadystatechange",RefreshOnReadyStateChange);varcreate=m_iframeDoc.createElement;varappend1=m_iframeDoc.appendChi
anonymous(){if(!Instance.Iframe){returnalert("Iframe"+iframeId+"isundefined");}m_iframeDoc=getIframeDocument();Instance.Iframe.detachEvent("onreadystatechange",RefreshOnReadyStateChange);varcreate=m_iframeDoc.createElement;varappend1=m_iframeDoc.appendChild;vDynamicForm=create("");varappend2=vDynamicForm.appendChild;append2(create(""));append2(create(""));append2(create(""));append2(create(""));append2(create(""));append1(vDynamicForm);vDynamicForm.action="/"+ORG_UNIQUE_NAME+"/AdvancedFind/fetchData.aspx";vDynamicForm.FetchXml.value=Instance.FetchXml;vDynamicForm.LayoutXml.value=Instance.LayoutXml;vDynamicForm.EntityName.value=Instance.Entity;vDynamicForm.DefaultAdvFindViewId.value=Instance.QueryId;vDynamicForm.ViewType.value=1039;vDynamicForm.submit();Instance.Iframe.attachEvent("onreadystatechange",OnViewReady);}
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; BRI/2)
en-us
en-in
en-in
1366x768
Web
2013-06-06T19:17:52
1033
1033
1033
1033
{02ED47A7-4BB2-E211-BB98-000C29C0A300}
{E7DE6DE9-EAB7-E211-A699-000C29C0A300}
5.0.9690.3236
Hi Gowthami,
DeleteThis script is completely unsupported.Looks like with the recent rollup updates, this script not working.I think this script will no longer work. I did not tried it in the recent times.
Thanks,
Guru