locked
Hiding "Add" button from campain RRS feed

  • Question

  • Hi there,

    I want to hide "add" button from the "Target Marketing List" section on the campaign form.

    I am following http://dmcrm.blogspot.com/2008/01/hiding-buttons-in-mscrm-40.html link.

    But i am not able to locate the title for the "add" button for adding new marketing list.

    What i am trying to do is, i want only one marketing list to a campaign. I have already written the java script which checks if there is already a marketing list associated with a campaign or not.

    Please advice!
    Monday, May 18, 2009 11:37 PM

Answers

  • Hi.

    Add following script to OnLoad handler of campaign form:

    function test()
    {
    	var _frame = document.getElementById('areaTargetListsFrame');
    	if (_frame != null)
    	{
    		clearInterval(intervalid);
    
    		var doc = _frame.contentWindow.document;
    
    		if (doc.readyState == 'complete')
    		{
    			var button = doc.getElementById('_MBtoplocAssocObjListsubTypetargetLists1');
    			if (button != null)
    				button.outerHTML = '';
    		}
    	}
    }
    
    var intervalid = setInterval(test, 1000);

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, May 19, 2009 6:56 AM
    Moderator
  • Hi
       This is a bit modified version of code
    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
    function HideAssociatedViewButtons(loadAreaId, navElementId, buttonIDs)
    {
        var navElement = document.getElementById(navElementId); 
        if (navElement != null)   
        {
            navElement.onclick = function LoadAreaOverride()
            {
                loadArea(loadAreaId);
                HideViewButtons(document.getElementById(loadAreaId + 'Frame'), buttonIDs);
            }
        }
    }
    function HideViewButtons(Iframe, buttonIDs) 
    { 
        if (Iframe != null ) 
        {
            Iframe.onreadystatechange = function HideButtons() 
            { 
                if (Iframe.readyState == 'complete') 
                { 
                    var iFrame = frames[window.event.srcElement.id]; 
                    var liElements = iFrame.document.getElementsByTagName('li'); 
                    for (var j = 0; j < buttonIDs.length; j++) 
                    { 
                        for (var i = 0; i < liElements.length; i++) 
                        { 
                            if (liElements[i].getAttribute('id').indexOf(buttonIDs[j]) >= 0) 
                            { 
                                liElements[i].innerHTML = '<SPAN style="display:none"><A><IMG></IMG><SPAN></SPAN></A></SPAN>';
                                break;
                            }
                        } 
                    } 
                } 
            } 
        }
    }
    Put it in your OnLoad event. It is for Update Rollup 4. In earlier rollups this line
    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
    might need to be changed depends on IDs.
    everything is a matter of probability...
    Tuesday, May 19, 2009 8:26 AM
  • Hi.

    If your goal to hide button when there are already present at least one marketing list change code

                if(results.length > 1)
                {
                    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
                    clearInterval(intervalid);
                }
    

    to

                if(results.length >= 1)
                {
                    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
                    clearInterval(intervalid);
                }
    

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Wednesday, May 20, 2009 6:18 AM
    Moderator

All replies

  • Hi.

    Add following script to OnLoad handler of campaign form:

    function test()
    {
    	var _frame = document.getElementById('areaTargetListsFrame');
    	if (_frame != null)
    	{
    		clearInterval(intervalid);
    
    		var doc = _frame.contentWindow.document;
    
    		if (doc.readyState == 'complete')
    		{
    			var button = doc.getElementById('_MBtoplocAssocObjListsubTypetargetLists1');
    			if (button != null)
    				button.outerHTML = '';
    		}
    	}
    }
    
    var intervalid = setInterval(test, 1000);

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Tuesday, May 19, 2009 6:56 AM
    Moderator
  • Hi
       This is a bit modified version of code
    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
    function HideAssociatedViewButtons(loadAreaId, navElementId, buttonIDs)
    {
        var navElement = document.getElementById(navElementId); 
        if (navElement != null)   
        {
            navElement.onclick = function LoadAreaOverride()
            {
                loadArea(loadAreaId);
                HideViewButtons(document.getElementById(loadAreaId + 'Frame'), buttonIDs);
            }
        }
    }
    function HideViewButtons(Iframe, buttonIDs) 
    { 
        if (Iframe != null ) 
        {
            Iframe.onreadystatechange = function HideButtons() 
            { 
                if (Iframe.readyState == 'complete') 
                { 
                    var iFrame = frames[window.event.srcElement.id]; 
                    var liElements = iFrame.document.getElementsByTagName('li'); 
                    for (var j = 0; j < buttonIDs.length; j++) 
                    { 
                        for (var i = 0; i < liElements.length; i++) 
                        { 
                            if (liElements[i].getAttribute('id').indexOf(buttonIDs[j]) >= 0) 
                            { 
                                liElements[i].innerHTML = '<SPAN style="display:none"><A><IMG></IMG><SPAN></SPAN></A></SPAN>';
                                break;
                            }
                        } 
                    } 
                } 
            } 
        }
    }
    Put it in your OnLoad event. It is for Update Rollup 4. In earlier rollups this line
    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
    might need to be changed depends on IDs.
    everything is a matter of probability...
    Tuesday, May 19, 2009 8:26 AM
  • This works great! Thanks alot for the quick response!

    One more thing related to this. Right now with the help of your script, i can hide the add button only on OnLoad event. So whats happening is onLoad the script queries the crm and finds out how many marketing lists are associated with this campaign. If there is more than one marketing list, then it hides the add button. and if there is not any marketing list then it makes the button visible.

    After that user adds a marketing list, but at this point it does not check for the number of marketing lists. and keep the "add" button visible and with that user can add more than one marketing list to the campaign.

    Is there a way i can refresh the page as soon as i add the marketing list?

    I Tested a33ik's method of SetInterval also. Which will work, but this is will keep running regardless of marketnig list is added or not. Is there a way i can put a check on that?

    One more thing i noticed, that if user add a member list to campaign, and close the form without saving it, the marketing list stays there. Is there a way i can write javascript event for the close action of the form.Becuase if user save the content, i can write a javascript to remove the lately added marketing list from the campaign with a popup notice to user.

    Thanks!

    • Edited by LearnQuick Tuesday, May 19, 2009 1:32 PM
    Tuesday, May 19, 2009 1:15 PM
  • Hi a33ik,

    Below is the script i am using. Everything else is working other than the set interval method does not seem to be running perfectly.
    Can you please have a look and see what exactly i am missing.
    function HideAddButton()
    {
    var cid = crmForm.ObjectId;
    var strCampaignId = cid.substring(1,37);
    
                var fetchMapping = "logical";
                var entityName = "campaignitem";
                var firstColumn = "campaignid";
                //var secondColumn = "entityid";
                var filterType = "and";
                var conditionAttribute = "campaignid";
                var operator = "eq";
                var value = strCampaignId;
                //alert(value);
                var authenticationHeader = GenerateAuthenticationHeader();
    
                // Prepare the SOAP message.
               var xml = "<?xml version='1.0' encoding='utf-8'?>" +
                    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
                    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
                    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
                    authenticationHeader +
                    "<soap:Body>" +
                    "<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
                    "<fetchXml>&lt;fetch mapping='" + fetchMapping + "'&gt;" +
                    "&lt;entity name='" + entityName + "'&gt;" +
                    "&lt;attribute name='" + firstColumn + "'/&gt;" +
                    //"&lt;attribute name='" + secondColumn + "'/&gt;" +
                    "&lt;filter type='" + filterType + "'&gt;" +
                    "&lt;condition attribute='" + conditionAttribute + "'" +
                    " operator='" + operator + "' value='" + value + "'/&gt;" +
                    "&lt;/filter&gt;" +
                    "&lt;/entity&gt;" +
                    "&lt;/fetch&gt;</fetchXml>" +
                    "</Fetch>" +
                    "</soap:Body>" +
                    "</soap:Envelope>";
    
                //alert(xml);
    
                var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
                xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
                xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
                xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                xHReq.setRequestHeader("Content-Length", xml.length);
                xHReq.send(xml);
                var resultXml = xHReq.responseXML;
                //alert(resultXml.xml);
                var result = resultXml.xml;
                result = result.replace(/\&amp;/g, '&');
                result = result.replace(/\&lt;/g, '<');
                result = result.replace(/\&gt;/g, '>');
                result = result.replace(/\&quot;/g, '"');
                result = result.replace(" paging-cookie=\"", ">");
                result = result.replace("</cookie>\">", "</cookie>");
               // alert("result: ---------" + result);
    
                // Create an XML document that you can parse.
                var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                oXmlDoc.async = false;
                // Load the XML document that has the UnEncoded results.
                oXmlDoc.loadXML(result);
                // Display the results.
                var results = oXmlDoc.getElementsByTagName('result');
                //alert(results);
                //alert(results.length);
                if(results.length > 1)
                {
                    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
                    clearInterval(intervalid);
                }
    }
    
    var intervalid = setInterval(HideAddButton, 1000);
    
    function HideAssociatedViewButtons(loadAreaId, navElementId, buttonIDs)
    {
        var navElement = document.getElementById(navElementId); 
        if (navElement != null)   
        {
            navElement.onclick = function LoadAreaOverride()
            {
                loadArea(loadAreaId);
                HideViewButtons(document.getElementById(loadAreaId + 'Frame'), buttonIDs);
            }
        }
    }
    function HideViewButtons(Iframe, buttonIDs) 
    { 
        if (Iframe != null ) 
        {
            Iframe.onreadystatechange = function HideButtons() 
            { 
                if (Iframe.readyState == 'complete') 
                { 
                    var iFrame = frames[window.event.srcElement.id]; 
                    var liElements = iFrame.document.getElementsByTagName('li'); 
                    for (var j = 0; j < buttonIDs.length; j++) 
                    { 
                        for (var i = 0; i < liElements.length; i++) 
                        { 
                            if (liElements[i].getAttribute('id').indexOf(buttonIDs[j]) >= 0) 
                            { 
                                liElements[i].innerHTML = '<SPAN style="display:none"><A><IMG></IMG><SPAN></SPAN></A></SPAN>';
                                break;
                            }
                        } 
                    } 
                } 
            } 
        }
    }
    Tuesday, May 19, 2009 6:54 PM
  • Hi.

    If your goal to hide button when there are already present at least one marketing list change code

                if(results.length > 1)
                {
                    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
                    clearInterval(intervalid);
                }
    

    to

                if(results.length >= 1)
                {
                    HideAssociatedViewButtons('areaTargetLists','navTargetLists',['_MBtoplocAssocObjListsubTypetargetLists1']);
                    clearInterval(intervalid);
                }
    

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Wednesday, May 20, 2009 6:18 AM
    Moderator
  • Thanks a33ik,

    I think i did not explain it well. Here is the scenario

    user opens the campaign form. The onload script runs and check if there is 1 or more than 1 marketing lists associated. it makes the add button invisible. --> Upto here your script is perfect

    but if user removes the existing marketing list, the add button should become visible. But in present case the add button is still invisible even though there is no marketing list associated with the campaign. Unless user reload the page, the add button stays invisible.

    Can we do something about this?

    Thanks!

    Wednesday, May 20, 2009 1:28 PM
  • Hi there ,

    any clue about this? anyone?

    thanks!
    Thursday, May 21, 2009 2:30 PM