Thursday, May 19, 2011

Customizing BasicHomeTab



So I've been banging my head against the wall trying to figure out how to add a button to the BasicHomeTab in CRM 2011. And if you googled around, you aren't going to find many samples out there. Finally I had a Eureka moment!


I decided to do a blog post to help the masses out there.

First thing you should do is create a new solution in CRM 2011. Once you have created it, you should add existing "Application Ribbon'. This will pull in your instance's application ribbon into your solution. Save your solution. Then export the solution. You will obviously save it to somewhere on your machine that you can get to. Unzip the file.

You will have 3 XML files and a Web Resources folder to where you unzipped it. Open the Customizations.xml file in VS2010 or any text editor (e.g. Notepad)

What you are looking for is CustomAction node.

So here is a quick sample I whipped up.



Save your Customization.xml file once you have the right nodes updated with the above. Take all 3 XML files and the Web Resources folder, and zip it back up. Import back into CRM 2011. Publish all Customizations. Refresh your browser window once it is done. Go to Resource Center or any non-CRM sitemap link you have. And there you have a button.

Now if your goal is to have that button everywhere. You will need to add a button to the Location of Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab.ExportData.Controls._children. And make sure the Sequence number is greater than 70. This will put the button after the Advanced Find button. Also important is the TemplateAlias. TemplateAlias should be o3 for entity ribbon adds instead of isv.

Enjoy!





Monday, April 18, 2011

The easiest option is sometimes not the best.

In my years of CRM, the one thing that makes me cring is the dreaded optionset (picklist) field. What's so bad about it?

It always starts off with a set number of choices. Then you get requests to add more options. Or worse, add the dreaded "Other". "Other" then requires another field to store that value. Now you must be thinking...how many times has this guy faced "Other". But the truth is that I've learned to ask specific questions during the requirements phases of a CRM implementation. "Other" brings chaos. Users will put all sorts of garbage in that Other field. Where this all becomes any issue is if you have to do any reporting and aggregation on that field. Then everyone looks at the "Other" field and want to add that to the list of options. It's a cursed cycle.

While in CRM 2011, optionsets are much more flexible with global usage options. I am still partial to using a little Javascript to account for impending "Other". I take a standand CRM text (navchar) field. Add on a webresource with a script that transforms the text field into a picklist OnLoad of the form. One field...multiple options, and you could even have the user to select "Other", and the text field would reveal itself. I've even been asked to only show existing values of other records as options.

There is always another way to skin a cat, but then you have a bald cat.

Saturday, August 21, 2010

Getting the actual day of the week from a date field

It's the simple things that I sometimes get stuck on. For the longest time, I couldn't figure out how to garner the actual day of the week from a date field value.

Now I share how ridiculously simple it is using Jscript.

var date = crmForm.all.pai_dateworked.DataValue;
var pai_name
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
pai_name = weekday[date.getDay()];
crmForm.all.pai_name.DataValue = pai_name;

Saturday, August 14, 2010

Save the last viewed tab

I've had alot of clients to ask me about this. Keep in mind that this is really for CRM 4.0.
The scenario goes that you may be asked to perform some save events that happens on a form. The form has a couple of tabs, and the save event happens on the 3rd tab. The form reloads back on the first tab. It gets pretty annoying especially when you have alot of tabs (not saying some CRM dev might have hacked the number of tabs on a form).





function OnCrmPageLoad()
{
if( crmForm.FormType == 2)
RetainTab();
}

function RetainTab()
{
crmForm.attachEvent( "onsave" , OnCrmPageSave );
var regTab = new RegExp( window.name + "=(\\d)","gi");
regTab.exec(document.cookie);
var tab = document.getElementById("tab"+RegExp.$1+"Tab");
if( tab ) tab.click();
}

function OnCrmPageSave()
{
var crmTabBar = document.all.crmTabBar;
for(var i = 0 ; i < cookie =" window.name+"="+i;
break;
}
}
}

OnCrmPageLoad();

Sunday, February 28, 2010

IFrame + HTML + CRM Forms

One of my clients asked me to make "pretty column headers" for a 4 column section on his Opportunity form. Most of the code samples I've seen from other consultants often tell you to add a text field and customize it. Well, it becomes pointless if you have to make 4 fields just to re-transform into something "pretty" and not store a state of field.

You can add an iframe with a target of about:blank and then add this to your form Onload event. Oddly, I rarely see anyone mention this.

crmForm.all.IFRAME_SomeIFrame_d.innerHTML ="Look at me!";


So that you understand what that means. Here is the break down.

"crmForm.all.IFrame_SomeIFrame" - is the name of the element.
"_d.innerHTML" - is the attribute of this element.
"";" - simple HTML mark up of the text of Look at me!".

This had a ton of uses if you end up with a heavy customization of MSCRM. Rather than have it equal the code itself...you could have it equal a CRM field. Note you SHOULD use a nvachar text area field rather than a NTEXT field or any other choice. Make sure you make the field length large enough to hold your code...I use 500. Now you can put that HTML code in the form and it would show OnLoad. Very important if you want to say, make an HTML signature for each user.


Update:

Looks like some the HTML tags you could use from this have been depreciated. Use this instead.

document.getElementById("IFRAME_CCNotesOffice_d").innerHTML = "
Notes from the Office

";