CRM: Disable Notes via javascript on the form

Here’s a script that I have used for a while now to disable notes on a form.  Typically I would use this on the disabled form of an entity in which we do not want further notes to be added (for whatever reason).

function DisableNotes()
{
    var iframe = document.getElementById("notescontrol");
    if (iframe.readyState == 'complete') {
        //Hide 'Create a New Note' link
        var notesButton = window.frames[0].document.getElementById('newNoteButton');
        notesButton.style.visibility="hidden";
        var NotesTable = window.frames[0].document.getElementById('NotesTable');

        //Disable the entire table
        NotesTable.disabled = true;
        var TextArea = NotesTable.getElementsByTagName('TEXTAREA');

        //It's still necessary to individually disable the Textareas where users edit the existing notes.
        for (i=0;i<TextArea.length;i++)
        {TextArea[i].Disabled = true;}
    }

    return;
}

To use it on a disabled form you would add something like the following to a form load event:

/* OnLoad Event */
function Incident_OnLoad()
{
    // Check if the Form is in Disabled mode; if so make the notes Read-Only
    if(Xrm.Page.ui.getFormType() == 4)
    {
        var iframe = document.getElementById("notescontrol");
        iframe.attachEvent('onreadystatechange', DisableNotes);
    }
}

2 Responses to “ “CRM: Disable Notes via javascript on the form”

  1. Priyank Jain says:

    We can also achive this by using below code….

    function DisableNotes() {

    var noteControl = document.getElementById(“notescontrol”);
    var noteTable = noteControl.contentWindow.document.getElementById(“NotesTable”);
    noteTable.disabled = true;

    var textArea = noteTable.getElementsByTagName(‘TEXTAREA’);

    for (i = 0; i < textArea.length; i++) {
    textArea[i].disabled = true;
    }

    return;
    }

    • gary says:

      Do you know how to do this CRM 2013. Looks like – “contentWindow” is not present in it.

      ANy help would greatly be appreciated.

      Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *