One of the most common operations we do is to hide certain buttons within the CRM using DHTML. This ought to have been relatively easy and using CRM3 it was. You simply used the following :
document.getElementById('[yourcontrolnamehere]').style.display = "none";
Unfortunately, things have changed in CRM 4 and not for the better. In CRM 4.0 there is some auto-incremented number or randomly generated number that gets placed at the end of all of the ElementId's on a page. Which means that the code used for CRM 3.0 will break.
Recently, due to some operational reasons, my client wanted to disable the 'Convert Campaign Response' button on the Campaign Response Form.
So, there are a number of ways this can be achieved. First of all, we need to know the actual name of the control we are about to hide. I find that the IE Developer ToolBar is one of the very best methods of achieving this. You can download the tool bar from HERE . When you have downloaded and installed the toolbar, you will be able to use it to find the actual name of the control inside CRM.
1) Navigate to the form you wish to check
2) Press F11 and then the Toolbar Icon
3) Click 'Find' and then 'Select Element By Click'
4) Select the button that you want to hide.
This handy little tool gives you the names of all elements on the page and now, all you have to do is hide them. There are a number of solutions out there.
Solution Number One
var Hide = function(menuItem){
if (document.getElementById(menuItem) != null)
{
document.getElementById(menuItem).style.display = "none";
}
}
var RemoveSpacerAfter = function(menuItem){
if (document.getElementById(menuItem) != null)
{
var item = document.getElementById(menuItem);
if (item.nextSibling != null)
item.nextSibling.style.display="none";
}
}
Hide('_MBConvertResponse');
RemoveSpacerAfter('_MBConvertResponse');
Solution Number Two
//Get all of the List Elements
var lis = document.getElementsByTagName('LI');
var i = 0;
//Loop through the list items
while (i < lis.length) {
//Don't worry about any list item that doesn't have the title you are looking for.
if (lis[i].getAttribute('title') == 'View directions to this account.')
{
//Replace the DHTML with blank tags to hide the button
lis[i].outerHTML='<SPAN></SPAN>'
}
i = i + 1;
}
You can also delete menu options from the Actions menu on any entity. Here's the same code again but removing the 'Delete Case' menu item from the Actions Menu
//Get all of the List Elements
var lis = document.getElementsByTagName('LI');
var i = 0;
//Loop through the list items
while (i < lis.length)
{
//Don't worry about any list item that doesn't have the title you are looking for.
if (lis[i].getAttribute('id') == '_MIonActionMenuClickdelete112')
{
//Replace the DHTML with blank tags to hide the button
lis[i].outerHTML='<SPAN></SPAN>'
}
i = i + 1;
}
Item Names
Item names are also fairly easy to figure out. You can view them by opening the relevant form, pressing Ctrl-N and then 'View', Source. Here are some basic ones that are much the same for all entities.
Actions Menu
Add Activity = _MIlocAddActTo4401
Add a Note = _MIlocAddObjTo5
Attach a file = _MIlocAddFileTo5
Delete Account = _MIonActionMenuClickdelete1 (Entity: Contact would be 2)
Mail Merge = _MIonActionMenuClickwebmailmerge1 (Entity:Contact would be 2)
Sharing = _MIonActionMenuClickshare1
General Buttons
Jewel Button = ms-crm-Menu-JewelButton
Save = _MBcrmFormSave
Save & Close = _MBcrmFormSaveAndClose
Print = _MBcrmFormPrint
A word of explanation for the Delete menu item. The number at the end of the id is in fact the ObjectTypeCode for the entity. So, the name of the delete button for the Accounts entity has the number 1 appended, contacts has the number 2 and so on. Once you have the hang of the naming conventions, it is pretty easy to guess what any given button or menu item is likely to be called. Once you have this information, you can view the source, search for the value and then confirm the correct information prior to applying the javascript.
Recent Comments