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.

- 5,304
- 2
- 32
- 57

- 758
- 5
- 21
- 43
-
Note field on which entity? Or are you trying to get values from a field on the Note entity? – Greg Owens May 21 '12 at 11:15
-
From any entities except Notes, say some custom entity.. – Charan Raju C R May 21 '12 at 11:25
-
Why do you need the name of the notes component? If you want to create notes, shouldn't you just be using something like http://www.bizforward.cws-international.com/2011/01/26/creating-records-in-crm-2011-using-javascript/ ? By default the notes component renders as an iFrame called 'notescontrol'. – glosrob May 21 '12 at 12:08
-
Yes, just now I got to know the name as 'notescontrol'. I thought of getting the Notes tab value by name. As its not an attribute, I could not get it. Just I need the description inside the Note Tab.. – Charan Raju C R May 21 '12 at 12:19
3 Answers
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.

- 637
- 1
- 9
- 20
-
I'm taking values of all the fields on click of some ribbon button. But I'm not able to get the text description inside Notes tab. You are telling to query for Annotations, but it might happen before saving the record. Just I need the description entered in Notes Tab.. – Charan Raju C R May 21 '12 at 12:16
-
If the note has been created then the annotation record will exist and should be queryable even if the record with which it is associated has not yet been saved. I could be wrong, but this should be easily testable by creating an annotation and then query for it using the oData RSS feed and see if it is returned or not. – Philip Rich May 21 '12 at 12:36
-
1Its creating Notes record before saving parent form only for Update form. Its not creating for Create form.. – Charan Raju C R May 21 '12 at 13:27
-
That makes sense as it can't associate itself with a record that hasn't been created yet. What exactly are you attempting to achieve with this functionality, some kind of validation? – Philip Rich May 21 '12 at 13:28
-
As soon as the notes control loses focus, the record is saved. If it is on the form, and the control does not have the focus, the note has been saved and can be retrieved by the SDK – glosrob May 21 '12 at 13:48
-
@PhilipRich: I'm taking the values of all the fields present on the form and creating an object with these values, to pass it as parameter in REST method, to Create a record programatically. – Charan Raju C R May 21 '12 at 13:56
-
So you are presumably firing an onSave event of some kind to query the unsaved records fields (via the Xrm.Page.data.entity collections) and creating another entity (say type X) whose fields are populated in some way based upon what the user entered when creating the initial record? Continued below... – Philip Rich May 21 '12 at 14:43
-
...I can see how maybe you may want to do this based upon an option set value or similar, but I'm struggling to see what you are doing from the notes field other than perhaps creating a task or activity whose description is a direct copy of the notes field on the original entity? If that is the case then I would probably go down the plug-in route anyway unless you are attempting to provide some real time feedback to the user about the newly created record? – Philip Rich May 21 '12 at 14:43
-
As I mentioned before, I'm taking all the field values from the form and creating one object which contains all these fields and calling REST Create method which will create a record with respective field values. I can all the values except Notes, so, I'm asking how to get the description present inside the Notes tab before saving it.. – Charan Raju C R May 22 '12 at 10:29
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;

- 3,878
- 1
- 18
- 42
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.

- 550
- 3
- 14