Thursday, December 3, 2009

CRM 4.0: Display Active and Inactive Records in a View

Microsoft CRM 4.0 does not allow you to view inactive records in views like the associated or quick find views. However with the removal of three lines in the xml, you can accomplish this.

Modifying the Quick Find for the Lead Entity to show both Active and Inactive Records

1. Export the entity customization that you want to modifiy.

2. Before modifying the customization, create a backup of the xml file, in case an error occurs when trying to import.

3. Below is the code for a lead. Find the savequery tag with a description containing "Quick Find". This is not the entire lead xml; I'm only showing the quick find saved query portion. The section outlined in red should be removed and the section outlined in green should be changed.

click image to enlarge


4. Import the customization, publish the entity, and test.

Thursday, April 30, 2009

Hide/Remove Items from the Entity Menu Toolbar in CRM 4.0

I recently had a request to remove or hide an item from the Entity menu toolbar in CRM 4.0.

Let's take the opportunity for example. If you had a business process reason that did not want your users to be able to close opportunities, and roles do not provide the ability to hide this, then I would write some client side javascript that would remove the link from the actions menu when the form loads.

First, you need to find the id of the item you wan to remove/hide. Using the code below on the onLoad event when updating, you can add alerts for each item.




var li = document.getElementsByTagName('LI');
var i = 0;

while(i < li.length)
{
alert(li[i].getAttribute('id'));
i = i + 1;
}




The one we are looking for is the "Close Opportunity" which is after "Recalculate" and before "Assign". Note: I would not do this on production as it will become very annoying for users.



First it will loop through all the File Menus, then the Toolbar, ending with the Action links. The first one in the image below is the Actions dropdown (action). It then goes through the activities and some other links until we see the Recalculate id (_MIcrmFormSubmitCrmForm1truetureflase) which is followed by Close Opportunity (_MIcomplete), followed by a break (), followed by the Assign link (_MIassignObject3).



So we now know the id of the link we want to remove/hide, _MIcomplete. Now we will hide this link when the form loads on update with the following code.




var CRMFORMTYPE_CREATE = 1;
var CRMFORMTYPE_UPDATE = 2;
var CRMFORMTYPE_READONLY = 3;
var CRMFORMTYPE_DISABLED = 4;
var CRMFORMTYPE_QUICKCREATE = 5;
var CRMFORMTYPE_BULKEDIT = 6;

if(crmForm.FormType == CRMFORMTYPE_UPDATE)
{
var li = document.getElementsByTagName('LI');
var i = 0;

while(i < li.length)
{
if (li[i].getAttribute('id') == '_MIcomplete')
{
li[i].outerHTML='<SPAN></SPAN>';
}
i++;
}
}




Now the link has been removed.



I've had cases where the above code did not hide buttons, so instead I had to use this:
document.getElementById('_MBCloseInvoice3').style.display = "none";

Programming with Josh

Welcome to my first blog. My blog will mainly cover programming with emphasis on asp.net windows and web development along with Microsoft CRM.