Saturday, February 16, 2008

MSCRM 4.0 Client: Hiding Buttons by Id

To hide a button in MSCRM 4.0 with the button id:

    var objElement = document.getElementById('_MBcrmFormSaveAndClose');
    objElement.innerHTML='<SPAN><SPAN><SPAN><SPAN></SPAN></SPAN></SPAN></SPAN>';


A function can be created to show/hide buttons by providing the Button Id:

// show: bool. Show = true, Hide = false
// id: string. Button Id
// tags: string. Object to stored the HTML tags
crmForm.ShowButton = function(show, id, tags)
{
    // Retrieve relevant button element based on Id
    var objElement = document.getElementById(id);
    var returnValue = null;

    // Show Button
    if (show) 
    {
        // Ensure the HTML tags for showing button is available 
        if (tags != null) 
        {
            // Restore HTML tags for showing button
            objElement.innerHTML = tags;
        }
    }
    // Hide Button
    else
    {
        // Store the HTML tags so that it can be restored when showing button
        returnValue = objElement.innerHTML;
        objElement.innerHTML='<SPAN><SPAN><SPAN><SPAN></SPAN></SPAN></SPAN></SPAN>';
    }

    return returnValue;
}


To call the function to hide a button:

    crmForm.SaveAndCloseButtonTags = crmForm.ShowButton(false, 
        "_MBcrmFormSaveAndClose", crmForm.SaveAndCloseButtonTags);


To show the button:

    crmForm.SaveAndCloseButtonTags = crmForm.ShowButton(true, 
        "_MBcrmFormSaveAndClose", crmForm.SaveAndCloseButtonTags);


To remove the button completely:

    var objElement = document.getElementById('_MBcrmFormSaveAndClose');
    objElement.outerHTML='<SPAN><SPAN><SPAN><SPAN></SPAN></SPAN></SPAN></SPAN>';

No comments: