Answered by:
How to hide the New Opportunity button on the Opportunities area on the Contact form?

Question
-
One of my customers has changed the Potential Customer field on the opportunity form to Primary Company, as they only want users to use this field associate the opportunity with an accounts and not contacts. However, users are sometimes creating a new opportunity from a contact record so I'd like to hide the New Opportunity button on the Opportunities grid.
I've tried following the sample code in these blog articles, but after a couple of hours of trying, I can't get any variations of my code to work.
- http://dmcrm.blogspot.com/2008/01/hiding-buttons-in-mscrm-40.html
- http://blog.davehawes.com/post/2008/04/23/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx
- http://www.eggheadcafe.com/software/aspnet/33685036/hiwith-javascript-you-can-hide-whatever-you-want-in-your-left-menu-you.aspx
Any ideas?
Neil Benson, CRM Addict and MVP at Customery Ltd.You can reach me on LinkedIn or Twitter.
Wednesday, August 11, 2010 3:47 PMModerator
Answers
-
Hi.
Try this - http://blog.davehawes.com/post/2008/04/23/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx
This code worked fine for me.
Also you can add following code to onload on opportunity:
if (crmForm.FormType == 1 && crmForm.all.customerid.DataValue != null && crmForm.all.customerid.DataValue[0].typename == 'contact')
{
crmForm.all.customerid.DataValue = null;
}
I must warn you what you will have issues with Lead qualification dialogue.
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)- Proposed as answer by Faisal Fiaz Wednesday, August 11, 2010 4:01 PM
- Marked as answer by Neil BensonMVP, Moderator Friday, August 13, 2010 8:59 AM
Wednesday, August 11, 2010 3:58 PMModerator
All replies
-
You could just clear the lookup value when the potential customer is of type contact, this would force the users to then select a new value.
MSCRM Bing'd - http://bingsoft.wordpress.comWednesday, August 11, 2010 3:55 PMModerator -
Hi.
Try this - http://blog.davehawes.com/post/2008/04/23/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx
This code worked fine for me.
Also you can add following code to onload on opportunity:
if (crmForm.FormType == 1 && crmForm.all.customerid.DataValue != null && crmForm.all.customerid.DataValue[0].typename == 'contact')
{
crmForm.all.customerid.DataValue = null;
}
I must warn you what you will have issues with Lead qualification dialogue.
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)- Proposed as answer by Faisal Fiaz Wednesday, August 11, 2010 4:01 PM
- Marked as answer by Neil BensonMVP, Moderator Friday, August 13, 2010 8:59 AM
Wednesday, August 11, 2010 3:58 PMModerator -
Thanks Andriy, what ID did you try using for the New Opportunity button? I tried "NavOpps" and "_MBlocAddRelatedToNonForm32GUID" but neither seemed work. My customer doesn't use leads, but I'll add your warning to my code's comments just in case they use leads later.
If I can't hide the button, I'll clear the value if the Potential Customer (Primary Company) field using your sample (like Rhett suggested).
Thanks!
Neil Benson, CRM Addict and MVP at Customery Ltd.You can reach me on LinkedIn or Twitter.
Wednesday, August 11, 2010 5:05 PMModerator -
Try to use following code, Neil:
It worked fine for me.HideAssociatedViewButtons(['Add a new Opportunity to this record']); function HideAssociatedViewButtons(buttonTitles){ var navElement = document.getElementById('navOpps'); if (navElement != null) { navElement.onclick = function LoadAreaOverride() { loadArea('areaOpps'); HideViewButtons(document.getElementById('areaOppsFrame'), buttonTitles); } } } function HideViewButtons(Iframe, buttonTitles) { if (Iframe != null ) { Iframe.onreadystatechange = function HideTitledButtons() { if (Iframe.readyState == 'complete') { var iFrame = frames[window.event.srcElement.id]; var liElements = iFrame.document.getElementsByTagName('li'); for (var j = 0; j < buttonTitles.length; j++) { for (var i = 0; i < liElements.length; i++) { if (liElements[i].getAttribute('title') == buttonTitles[j]) { liElements[i].style.display = 'none'; break; } } } } } } }
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)Wednesday, August 11, 2010 9:40 PMModerator -
Hi,
I have used following code to Hide new order button on Opportunity form ..see if you use this example on contact form...
areaOrdersFrame_OnReadyStateChange =
function()
{
if
(this.readyState == "complete")
{
/* This is the frame we're interested in */
var
frame = document.frames("areaOrdersFrame");
if
(frame !=null)
{
/* And this is the new order button on form */
var
newOrderButton = frame.document.getElementById("_MBparentcustomAddRelatedItem21");
if
(newOrderButton !=null)
{
newOrderButton.style.display =
'none';
newOrderButton.nextSibling.style.display =
'none';
}
}
}
}
/* Set a new onclick event for the History navigation element
* This is where we register the onreadystatechange event handler */
if
(document.getElementById('navOrders') != null) {
document.getElementById(
'navOrders').onclick = function() {
loadArea(
'areaOrders');
document.frames(
'areaOrdersFrame').document.onreadystatechange = areaOrdersFrame_OnReadyStateChange;
}
}
MayankP My Blog My twitter- Proposed as answer by Amarsen Vangoor Saturday, August 14, 2010 6:52 AM
Thursday, August 12, 2010 8:34 AM