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)

Related notes views in Account form -iframe

(0) ShareShare
ReportReport
Posted on by

Hi Friends,

I want to display related notes views on accounts page.I am doing iframe to show the view in accounts form.I am using the below code its not working any one can help me

/// <summary>
/// loadIFrame method will be main method which needs to be called to Load View into IFrame
/// Here in this example we will be dsiplaying primary contact's All Activities on the Account form
/// </summary>

function loadIFrame() {
// Xrm.Page.data.entity.getId()
// Get Primary Contact of Account
var GUIDvalue = Xrm.Page.data.entity.getId();
if (GUIDvalue != null) {

window.fetchActivtities = new FetchViewer("IFRAME_ShowView"); // IFRAME_ShowView = ID of Iframe
fetchActivtities.FetchXml = getFetchXml(GUIDvalue); // Pass primarycontact GUID as parameter
fetchActivtities.LayoutXml = getLayoutXml();
fetchActivtities.Entity = "annotation"; //Fetching entity schema name
fetchActivtities.QueryId = "{0414C221-4B00-E811-813A-0050568E1C5F}"; // view GUID, here its 'All Activities' view GUID
fetchActivtities.RegisterOnTab(1); //IFRAME TAB INDEX where Iframe located
}

}


/// <summary>
/// Gets FetchXML
/// </summary>
/// <param name="primarycontactId">Accounts Primary Contact ID</param>

function getFetchXml(primarycontactId) {

// FetchXML Query of view, you can get it from Adv. Find or Customizations.xml

return "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
" <entity name='annotation'>" +
"<attribute name='subject' />" +
"<attribute name='notetext' />" +
"<attribute name='modifiedby' />" +
"<attribute name='modifiedon' />" +
"<attribute name='ownerid' />" +
"<attribute name='filename' />" +
"<attribute name='createdon' />" +
"<attribute name='annotationid' />" +
"<order attribute='subject' descending='false' />" +
"<link-entity name='account' from='accountid' to='objectid' alias='aa'>" +
"<filter type='and'>" +
"<condition attribute='accountid' operator='eq' uitype='account' value='" + GUIDvalue + "' />" +
"</filter>" +
"</link-entity>" +
"</entity>" +
"</fetch>";

}


/// <summary>
/// Layout of Gridview
/// </summary>

function getLayoutXml() {

// grid layout, you can get easily from Customization.xml file
return "<grid name='annotations' object='5' jump='subject'" +
"select='1' icon='1' preview='1'>" +
"<row name='annotation' id='annotationid'>" +
"<cell name='subject' width='200' />" +
"<cell name='notetext' width='200' />" +
"<cell name='modifiedby' width='150' />" +
"<cell name='modifiedon' width='100' />" +
"<cell name='createdon' width='100' />" +
"<cell name='filename' width='100' />" +
"<cell name='ownerid' width='100' />" +
"</row>" +
"</grid>";

}

/// <summary>
/// Fetch IFrame content
/// </summary>
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();
}

/// <summary>
/// Loads Iframe with the view
/// </summary>
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;

var vDynamicForm = document.createElement("form");
vDynamicForm.setAttribute('method', "post");
vDynamicForm.setAttribute('name', "vDynamicForm");

var FetchXml = document.createElement("input");
FetchXml.setAttribute('type', "hidden");
FetchXml.setAttribute('name', "FetchXml");
vDynamicForm.appendChild(FetchXml);


var LayoutXml = document.createElement("input");
LayoutXml.setAttribute('type', "hidden");
LayoutXml.setAttribute('name', "LayoutXml");
vDynamicForm.appendChild(LayoutXml);


var EntityName = document.createElement("input");
EntityName.setAttribute('type', "hidden");
EntityName.setAttribute('name', "EntityName");
vDynamicForm.appendChild(EntityName);

var DefaultAdvFindViewId = document.createElement("input");
DefaultAdvFindViewId.setAttribute('type', "hidden");
DefaultAdvFindViewId.setAttribute('name', "DefaultAdvFindViewId");
vDynamicForm.appendChild(DefaultAdvFindViewId);


var ViewType = document.createElement("input");
ViewType.setAttribute('type', "hidden");
ViewType.setAttribute('name', "ViewType");
vDynamicForm.appendChild(ViewType);

m_iframeDoc.body.appendChild(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";
}

/// <summary>
/// Gets Iframe content
/// </summary>

function getIframeDocument() {
return Instance.Iframe.contentWindow.document;
}

}

*This post is locked for comments

I have the same question (0)

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