Wednesday, 25 November 2015

Hide ‘Add Existing Button’ or Plus (+) Button In CRM 2013 Subgrid

Brief Introduction

This requirement often comes and the only supported way is to either hide through Security Role (which in most cases this is not possible and using Ribbon Workbench to hide it), but sometimes you need to only hide in some forms and you need to hide all necessary ribbons using Ribbon Workbench (FYI, one of my favorite tool)
So here is the code to hide the + button for Subgrid:

The Code

function hideAddButtonSubgrid(subgridId) {
    try {
        addEventToGridRefresh(subgridId, setAddButtonDisplayNone);
    }
    catch (e) {

    }
}

function setAddButtonDisplayNone(subgridId) {
    var imageId = subgridId + "_" + "addImageButton";
    if (imageId) {
        document.getElementById(imageId).style.display = 'none';
    }
    //var imageId2 = subgridId + "_" + "addImageButtonImage";
    //document.getElementById(imageId2).style.display = 'none';
}

function addEventToGridRefresh(subgridId, functionToCall) {
    // retrieve the subgrid
    var grid = document.getElementById(subgridId);
    // if the subgrid still not available we try again after 1 second
    if (grid == null) {
        setTimeout(function () { addEventToGridRefresh(subgridId, functionToCall); }, 1000);
        return;
    }

    // add the function to the onRefresh event
    grid.control.add_onRefresh(functionToCall);

    var imageId = subgridId + "_" + "addImageButton";
    if (imageId) {
        if (document.getElementById(imageId).style.display.toLowerCase() == "block") {
            setAddButtonDisplayNone(subgridId);
        }
    }
}



How to Call


Just use this code to call:
hideAddButtonSubgrid("mysubgrid_name");



And here enjoy the result

Result


*Before:

image

*After applied:

image

*Note: This is undocumented in SDK, so use as per your own risk, I need this as the must-to-have requirement so that I have to try workaround to make it happened to the customer.

Hope this helps!
Thanks.

4 comments:

  1. Nice writeup about CRM. If you want to buy best crm software solutions please contact us from the links below


    The online CRM software topic of discussion here is very much serious as well as they are all counting regarding the CRM Software Solutions CRM tool as well as its advantages. Make this a must for your all custom crm solutions possibilities and within quick time you will start feeling up the change. Business as well as all related aspects is carefully managed by this new custom built crm tool.

    ReplyDelete
  2. The sales lead follow up article is very much point base and there are all details and crm management software important aspect counted about CRM. The point is very clear and the tool is already known to create all buzz in the market. There are custom crm development serious and higher end benefits found to work for the CRM tool. For every business it is something that is proving quite a dealer crm worth.

    ReplyDelete
  3. Hi, can i know the code should call it from where?

    ReplyDelete
  4. document.getElementById() is returning null value when I try to get the grid on a form.

    ReplyDelete

My Name is..