Deleting notes attachments using jscript in CRM 2011
Hi,
In CRM, we can add files as attachments to the Notes.
- All the notes get saved in to “Annotation” entity in the data base.
- The attachment information get saved in to below columns of “Annotation” entity
- Document Body
- File Name
- File Size
- Is Document
Deleting attachments using script:-
To delete the attachment using jscript,
- Update the “Document Body,File Name,File Size” fields to null
- And “IsDocument = false” using OData as below
function deleteAttachments(){
var notesId = {GUID of notes};
var objNotes = new Object();
objNotes.DocumentBody = null;
objNotes.FileName = null;
objNotes.FileSize = null;
objNotes.IsDocument = false;
updateRecord(notesId, objNotes, “AnnotationSet”);
}
function updateRecord(id, entityObject, odataSetName) {
var jsonEntity = window.JSON.stringify(entityObject);
var serverUrl = Xrm.Page.context.getServerUrl();
var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;
var updateRecordReq = new XMLHttpRequest();
var ODataPath = serverUrl + ODATA_ENDPOINT;
updateRecordReq.open(‘POST’, ODataPath + “/” + odataSetName + “(guid'” + id + “‘)”, false);
updateRecordReq.setRequestHeader(“Accept”, “application/json”);
updateRecordReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
updateRecordReq.setRequestHeader(“X-HTTP-Method”, “MERGE”);
updateRecordReq.send(jsonEntity);
}
🙂
Leave a Reply to angel humberto Cancel reply
Stats
- 1,465,804 hits
Translate
Categories
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- Useful JScript syntax's – ADX/Dynamics 365 Portals
- [Step by Step] Using TypeScript in Dynamics 365 9.x
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- Associate/Disassociate plugin messages in CRM
- 'Callback Registration Expander' System Jobs stuck at 'Waiting For Resources'
- Power Apps | Business Rule | Set Field Value vs Set Default Value
- Dynamics Portal - 'No list could be found with the relative URL' Error - Fix
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
where can i find the GUID of notes
Where can i find the GUID of notes
Hi,
To get the Note Id’s you can query ‘AnnotationSet’ using OrganizationData sevice.
For example, to get Notes associated with ‘Account’ with GUID (XXX-XX-XXX) below is the OData URL.
Url – https://rajeevlearnings.crm5.dynamics.com/xrmservices/2011/OrganizationData.svc/AnnotationSet?$filter=ObjectId/Id eq guid'{XXX-XX-XXX}’
This will give you Notes records for that Account, get Note GUID from the collection.