CRM 2011: Dynamically change sub-grid fetchXml – left navigation pane

In CRM 2011 account entity there are 2 left navigation links called Open Activities and Closed activities. When we select these, the sub-grid populates activites associated with the related contacts also. To filter them based on the regarding field we can use javascript to pass the fetchXml dynamically and change the view.

For this you need the IFrame id in which the grid gets loaded.

To get the IFrame control:

var frame = document.frames["areaActivitiesFrame"].frameElement;

Bind “onreadystatechange” event for the Iframe:

frame.onreadystatechange = function () {
if (event.srcElement.readyState == “complete”) {
BindGrid(“Open”, frame);
}
};

Get grid control and pass the fetchXml

function BindGrid(state, frame) {
var currentId = Xrm.Page.data.entity.getId();
var currentName = Xrm.Page.getAttribute(“name”).getValue();
var fetchXmlStr = getFetchXml(currentId, currentName, state);
fetchXmlStr += getFetchXml(null, null, state);
frame.contentWindow.document.getElementById(“AppGridFilterContainer”).style.display = “none”; //To hide filter
frame.contentWindow.document.getElementById(“newViewSelector”).innerText = state + “Activities:”; //Change the text
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers_SavedNewQuerySelector”).style.display = “none”;
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.setParameter(“fetchXmlForFilters”, fetchXmlStr);

frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.setParameter(“fetchXml”, fetchXmlStr);
frame.contentWindow.document.getElementById(“crmGrid_Account_ActivityPointers”).control.refresh();

}

After getting the grid contol you can make any changes you want in the grid: changing the header text, hiding elements inside the grid…

Thanks.

CRM 2011:Pass QueryString to left navigation Link

In CRM 2011, we can place a custom navigation link in the left navigation pane of a form. I had to add a custom aspx page in the left navigation pane and pass the record GUID to its querystring. To add the querystring dynamically we need to attach onclick event to the left navigation link label and then append the parameter and its value to the url.

NOTE: This overrides the default click event and you have to load the page through script.

The code goes like this:

function PassQryStrToLink() {
var navItems = Xrm.Page.ui.navigation.items.get();
for (var navItem in navItems) {
if (navItems[navItem].getLabel() == “OpenActivities”||navItems[navItem].getLabel()==”ClosedActivities”) {
var pageUrl = “”;
document.getElementById(navItems[navItem].getId()).onclick = function () {
//alert(“hi”);
var currentId = Xrm.Page.data.entity.getId();
var EltName = window.event.srcElement.parentElement.id;
if (Xrm.Page.ui.navigation.items.get(EltName).getLabel() == “OpenActivities”)
pageUrl = encodeURI(‘http://’ + window.location.hostname + ‘:81/Activities.aspx?id=’ + currentId + ‘&type=0′);
else if (Xrm.Page.ui.navigation.items.get(EltName).getLabel() == “ClosedActivities”)
pageUrl = encodeURI(‘http://’ + window.location.hostname + ‘:81/Activities.aspx?id=’ + currentId + ‘&type=1′);
loadIsvArea(Mscrm.CrmUri.create(pageUrl), false);
};
}
}
}

The Custom navigation link will have its id as “navLink{<GUID>}” where in the GUID will change for each organization. So we have to iterate through every navigation item and check with the label to find the id.

Placing an aspx page in the left navigation has a problem. Whenever any external page is loaded in the left navigation pane the Ribbon gets completely disabled. We cannot select any button until we change the form’s context by selecting someother options in left navigation pane. Any work around for this problem is welcome!!! Thanks in advance:)

Steps to deploy custom aspx page in CRM 2011

In CRM 2011 its not required to deploy it in ISV. We need to create a new web site. Firstly publish the solution to “/InetPub/wwwroot/<PublishFolderName>” or publish and copy the published files to the same path. Follow the below steps:

1. Goto IIS. Create a new website. Need not change the ApplicationPool. This should create a new ApplicationPool in the same name as the website. Specify a different port number which is not used by either CRM or any other websites. In Physical path give Published foler path in wwwroot(/InetPub/wwwroot/<PublishFolderName>).

2. Goto ApplicationPool and for the new ApplicationPool change the following properties:

  •  .Net FrameworkVersion – v4.0
  •  Managed Pipeline Mode – Classic (previously it will be Integrated)

3. Right click the ApplicationPool and Open advanced Settings. Change the Identity property to “Network Service”.

Thats it:) done deploying..

You can check it by selecting ur aspx page and select Browse. Make a note of the url from the IE window.

Refer these pages for more information about deploying aspx pages for CRM 2011:
Upgrade Code in the ISV folder to Microsoft Dynamics CRM 2011Deploying web applications inside MS CRM 2011 ISV folder

Thanks.

Attach OnClick event to all fields on the CRM 2011 Form and Passing querystring to silverlight web resource in the footer

Hi,
I came across a scenario that will attach a click event to all fields on the CRM 2011 form. There is a silverlight page on the footer of the form. On click of any field i need to pass the schema name of the source field(which raised the event) to the silverlight page.
Using the Xrm properties we cannot get the control of a control in the footer. Here I had to pass a dynamic parameter to the querystring of the silverlight web resource and the ‘setData’ method also cannot be used directly.

My approach was: on load of the form I attached events to all label fields on the form. For the web resource on the footer there is a property called ‘control’ which gave access to the ‘setData’ method. Initially I dont want any data parameter to be passed. So in the web resource properties i passed an empty string as data parameter. This allowed me to change the data parameter dynamically :-)

Following is the code I used for the above scenario.

function AttachAttributEvents() {
var attribs = Xrm.Page.data.entity.attributes.get();
var attribName = ”;
for (var i in attribs) {
attribName = attribs[i].getName();
if (attribName != “”) {
document.getElementById(attribName + ‘_c’).onclick = function () { //Attach events to the label of each attribute
var Elt = window.event.srcElement.parentElement.id;
var EltName = Elt.substring(0, Elt.length – 2);
document.getElementById(“WebResource_FieldInfo”).control.setData(EltName); //Pass Data parameter to the web resource
};
}
}
}

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: