Dynamics/ADX Portals – Create Notes using SDK
As part of an integration requirement, we had to create ‘Notes’ (i.e., Annotation) with attachment using SDK.
Key Notes:
- ‘Subject’ and ‘Notetext’ field values of Portal Notes follows a specific pattern than that of Dynamics. Values must be set as follows:
- Subject – Note created on {DateTime.Now.ToString()} by {Portal User Name} [contact:{PortalUserGUID}]
- If the Portal user name is ‘Rajeev P’ and Portal user GUID(i.e.,Contact record’s GUID) is ‘2510ae27-7289-e911-a958-001dd800d97c’, Subject will be Note created on {DateTime.Now.ToString()} by Rajeev P [contact:2510ae27-7289-e911-a958-001dd800d97c]
- Notetext – *WEB*
- Subject – Note created on {DateTime.Now.ToString()} by {Portal User Name} [contact:{PortalUserGUID}]
- If you don’t pass Portal User’s GUID in ‘Subject’ field, Portal shows the Notes record created by as User whom the Portal was configured.
Code to create Annotation:
Below is the code snippet
var noteSubject = “Note created on {DateTime.Now.ToString()} by Rajeev P [contact:2510ae27-7289-e911-a958-001dd800d97c]“;
var entAnnotation = new Entity(“annotation”);
entAnnotation[“subject“] = noteSubject;
entAnnotation[“notetext“] = “*WEB*”;
entAnnotation[“filename”] = {File_name}; // Set FileName
entAnnotation[“documentbody”] = {Base64String}; // Pass document body in Base64 format
entAnnotation[“isdocument”] = true;
entAnnotation.Attributes[“objectid”] = new EntityReference({RegardingSchemaName}, {RegardingGuid}); // Set Schema and GUID
entAnnotation.Attributes[“objecttypecode”] = {RegardingSchemaName}; // Set Schemavar noteId = crmService.Create(entAnnotation);
- Note : Replace values in {} with actual values.
🙂