Geeks With Blogs
Oh my god ... not another MS CRM blog Guenter vs. MSCRM

For one of my projects I had to extend the menu of the detail form of email entitiy in MS CRM 3.0 Unfortunately I could not do this using ISV.config because it only supports a handful of entities. Email is not one of them.
Fortunately MS CRM 3.0 supports java scripting on the onload event of the page. So I injected some new elements into the DOM to add another menu item to the actions menu. Of course this kind of HTML code injection into CRM pages is not something new, but the keypoint here is to use the "action" attribute of the table row element. I tried several possible solutions but it seems that this is the only possible solution to trigger the click event on the menu item.

Figure out the details with the following code snippet:

if(IsOnline()) // is only needed if the action has to be made online
{
    if (crmForm.FormType==2) // i only wanted the new menu item to appear on update forms
    { 
        // first get the current emailid if needed
        str=location.href;       
        erg=str.search(/id=[\{\}\dA-Fa-f\-]/);
       
        add='';
       
        if(erg!=1)
        {
            add='?' + str.substring(erg);
        }
       
        // don't blame me vor chosing variable names - i was in a hurry :-)
        trSpacer=document.createElement('tr');
        trSpacer.setAttribute('class', 'mnuSpacer');
        
        tdSpacer1=document.createElement('td');
        tdSpacer2=document.createElement('td');
        tdSpacer2.setAttribute('class', 'mnuSpacer');
        tdSpacer2.colspan='2';
        brSpacer=document.createElement('br');
        tdSpacer1.appendChild(brSpacer);
        hrSpacer=document.createElement('hr');
        hrSpacer.setAttribute('class', 'mnuSpacer');
        tdSpacer2.appendChild(hrSpacer);   
       
        trSpacer.appendChild(tdSpacer1);   
        trSpacer.appendChild(tdSpacer2);       
      
        tr=document.createElement('tr');
       
        // the next line is the essential part
        // you can replace it with any javascript code you want
        // i did some redirection to my custom page
        // which messes a little bit around on the server
        // and then redirects back to the page 
        // of course an ajax based solution could be an alternative
 // separate several js statements with semcolons ;
        tr.action='location.replace(\'my.aspx' + add + '\');';       
       
        td1=document.createElement('td');
        td1.style.border='1px solid #dcdfe5';
        td1.innerHTML=' '
       
        td2=document.createElement('td');
        td2.style.border='1px solid #ffffff';
        td2.colspan='2';
        td2.innerHTML='Menu item name';
      
        tr.appendChild(td1);
        tr.appendChild(td2);
        document.getElementById('mnuaction').childNodes[1].appendChild(trSpacer);
        document.getElementById('mnuaction').childNodes[1].appendChild(tr);
   }
}

Maybe this is useful for someone out there.

Hf :-)

Posted on Tuesday, June 6, 2006 1:31 PM | Back to top


Comments on this post: MS CRM 3.0: Add menu items to detail forms of entities that are not supported in ISV.config

# re: MS CRM 3.0: Add menu items to detail forms of entities that are not supported in ISV.config
Requesting Gravatar...
I was actually looking to change the functionality of one of the "out of the box" functions of the actions menu, but this gave me another idea!

Thanks.
Left by Christopher Berry on Jun 18, 2008 2:45 AM

# re: MS CRM 3.0: Add menu items to detail forms of entities that are not supported in ISV.config
Requesting Gravatar...
Here is what I did to make it work in CRM 4.0

function AddButtonToActionMenu(id,action,text)
{
if (crmForm.FormType==2)
{
liElement=document.createElement('LI');
liElement.setAttribute('class','ms-crm-MenuItem-Label');
liElement.setAttribute('id',id);
liElement.action=action;

spanElement1=document.createElement('SPAN');
spanElement1.setAttribute('class','ms-crm-MenuItem-Label');

aElement=document.createElement('A');
aElement.setAttribute('class','ms-crm-MenuLink');
aElement.onclick='return false;';
aElement.href='javascript:onclick();';

spanElement2 = document.createElement('SPAN');
spanElement2.setAttribute('class','ms-crm-MenuItem-Icon');

spanElement3 = document.createElement('SPAN');
spanElement3.setAttribute('class','ms-crm-MenuItem-Text');
spanElement3.innerHTML=text;
aElement.appendChild(spanElement2);
aElement.appendChild(spanElement3);

spanElement1.appendChild(aElement);

liElement.appendChild(spanElement1);
if(document.getElementById('mnuaction')!=null)
{
if(document.getElementById('mnuaction').childNodes.length > 0)
{
var childElementLength = document.getElementById('mnuaction').childNodes.length -1;
document.getElementById('mnuaction').childNodes[childElementLength].appendChild(liElement);
}
}
}
}

function AddSpacerToActionMenu()
{
if (crmForm.FormType==2)
{
liElement=document.createElement('LI');
liElement.setAttribute('class','ms-crm-MenuList-Spacer');

hrElement=document.createElement('HR');
hrElement.setAttribute('class','ms-crm-MenuList-Spacer');

liElement.appendChild(hrElement);
if(document.getElementById('mnuaction')!=null)
{
if(document.getElementById('mnuaction').childNodes.length > 0)
{
var childElementLength = document.getElementById('mnuaction').childNodes.length -1;
document.getElementById('mnuaction').childNodes[childElementLength].appendChild(liElement);
}
}
}
}

if(!crmForm.all.new_submitforapproval.checked || !crmForm.all.new_unfreezeform.checked || !crmForm.all.new_approvalconfimation.checked)
{
AddSpacerToActionMenu();
}
if(!crmForm.all.new_submitforapproval.checked)
{
AddButtonToActionMenu('_SubmitForApproval','prompt(\'Outer XML of button\', document.getElementById(\"mnuaction\").outerHTML);','Submit for Approval');
}

if(crmForm.all.new_submitforapproval.checked && !crmForm.all.new_approvalconfimation.checked)
{
AddButtonToActionMenu('_ConfirmApproval','prompt(\'Outer XML of button\', document.getElementById(\"mnuaction\").outerHTML);','Confirm Approval');
}

if(crmForm.all.new_submitforapproval.checked || crmForm.all.new_approvalconfimation.checked)
{
AddButtonToActionMenu('_UnfreezeReferral','prompt(\'Outer XML of button\', document.getElementById(\"mnuaction\").outerHTML);','Unfreeze Referral');
}
Left by Apurva Desai on Jul 23, 2010 6:52 AM

Your comment:
 (will show your gravatar)


Copyright © Guenter Wallnoefer | Powered by: GeeksWithBlogs.net