Question

I need to set the Notes field to the Notes field value in other entity in CRM 2011 form. So, I need to know how get and set the Notes field using Javascript. And I'm not able to get the name of Notes field inside the section as you can seen in the below image.

enter image description here

Was it helpful?

Solution

OK there are two approaches required here.

@Philip_Rich pointed out that annotations for existing records are created as soon as they lose focus and can therefore be queried. You should be able to find existing code for this quite easily (if not, ask here).

You yourself acknowledged that for new (unsaved) records, annotations are not saved until after the parent record is saved. There is no supported way to access the value in the notes field at this point, however this nasty bit of code should get the value you seek. Beware that since it is unsupported, it is vulnerable to DOM changes in the forms:

var myNotesText = document.getElementById("notescontrol").contentWindow.document.getElementById("NotesTable").children[1].children[4].children[0].innerText;

OTHER TIPS

Notes in CRM are called 'annotations' under the hood. You create an annotation as you would any other CRM record type and then associate that annotation with the entity record of interest. I haven't attempted to retrieve notes fields from javascript explicitly (I've normally done this via a plug-in, which is documented in the SDK). However, I see no reason why you couldn't perform an oData query to retrieve annotations where the associated entity record was of entity type X for example.

In JS you don't need to do assign, you just create a note.

But you definetely need a created entity before you can attach a note to it.

Notes can be two types a note and an attachment.

Here is the example of how you can create a simple (text) note (annotation) from JS.

function _createAnnotation(entity, subject, text) {
    var orgService = GetOrganizationService();
    var annotation = {};
    annotation.Name = "annotation";
    annotation._properties = [];
    annotation._propertyTypes = [];
    annotation._properties['objectid'] = entity;
    annotation._propertyTypes['objectid'] = 'lookup';
    annotation._properties['subject'] = subject;
    annotation._propertyTypes['subject'] = 'string';
    annotation._properties['notetext'] = text;
    annotation._propertyTypes['notetext'] = 'string';
    annotation._properties['isdocument'] = 'false';
    annotation._propertyTypes['isdocument'] = 'boolean';
    annotation._properties['mimetype'] = 'text/html';
    annotation._propertyTypes['mimetype'] = 'string';
    orgService.Create(annotation);
}

Where:

entity - (EntityReference) of the entity you want to attach a note to.

subject - (String) Subject of a note.

text - (String) Body of a note.

If you want to attach an MS office document then you need to change isdocument and mimetype parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top