Wednesday, September 22, 2010

Remove Associated Buttons (Add Existing xxxxx to this record)

I recently had a request to remove the "Add Existing [entity name] to this record" button from the associated view for a client.

The below link is a great post on how to do this:

MSCRM 4 - Remove 'Add Existing xxxxx to this record' button by Dave Hawes

The only modification I made to this code was to use
liElements[i].outerHTML='<SPAN></SPAN>'; 

instead of
liElements[i].style.display = 'none';


My next post will discuss how to change the name of these associated buttons.

Friday, September 10, 2010

CRM 4.0 How to capture a Many to Many Event

After spending many hours trying to capture the on create of a many to many relationship, I found only 2 ways to do so:

1. Add a bit field that is set to true on load. This then requires the user to save the form. Create a workflow for when the bit field has changed. Then add to the workflow a condition when bit field is true followed by your process. End with the bit field being set to false.

  • Advantage: Requires minimal code and is supported by Microsoft.

  • Disdvantage: Upon every save (update) a workflow will fire. Not very optimal.



2. Create a trigger. The linker table exists inside the MSCRM database. On that table create a trigger that will perform your task when a new item is added.

  • Advantage: Only fires when new items are added.

  • Disdvantage: Not supported by Microsoft and the trigger will be removed upon Upgrade.

CRM 4.0 Hiding Navigation

Here is a great post on how to hide navigation.

Hiding Unwanted Navigation In CRM by Jeremy Winchell

Thursday, September 2, 2010

CRM Phone Number Formatting onChange with Extensions

Format Phone Numbers in CRM

Format (xxx) xxx-xxxx

var oField = event.srcElement;
if (typeof(oField) != "undefined" && oField != null && oField.DataValue != null)
{
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
if(sTmp.length == 10)
{
oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
}
else
{
alert('Phone must contain 10 numbers.');
}
}


Format xxx-xxx-xxxx

var oField = event.srcElement;
if (typeof(oField) != "undefined" && oField != null && oField.DataValue != null)
{
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
if(sTmp.length == 10)
{
oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
}
else
{
alert('Phone must contain 10 numbers.');
}
}


Format xxx.xxx.xxxx

var oField = event.srcElement;
if (typeof(oField) != "undefined" && oField != null && oField.DataValue != null)
{
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
if (sTmp.length == 10)
{
oField.DataValue = sTmp.substr(0, 3) + "." + sTmp.substr(3, 3) + "." + sTmp.substr(6, 4);
}
else
{
alert('Phone must contain 10 numbers.');
}
}


Other Formatting Issues:
Remove leading digit if number is 1

var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
if (sTmp.substr(0, 1) == "1")
{
sTmp = sTmp.substr(1, sTmp.length-1);
}


Allowing only 7 digits (no area code)

else if (sTmp.length == 7)
{
oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4);
}
else
{
alert('Phone must contain 7 or 10 numbers.');
}


Allowing extensions (requires area code)

else if (sTmp.length > 10)
{
oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4) + " ext: " + sTmp.substr(10, sTmp.length-10);
}
else
{
alert('Invalid phone number. If using an extension, you must enter area code also.');
}