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 Cancel reply
Stats
- 1,579,573 hits
Tweets
- RT @MikeFactorial: Big things are coming to the #CoEStarterKit. So, @ManuelaPichler_ and team are building the tension for the April releas… 2 weeks ago
- New blog post : Boost conversations using GPT in Power Virtual Agent (PVA) rajeevpentyala.com/2023/03/08/pow… 2 weeks ago
- RT @PPDevWeekly: 🔥 Going Live: Power Platform Dev Weekly 155 bit.ly/PPDevWeekly155 This week's cover story by @RajeevPentyala With gre… 2 weeks ago
- RT @caseyburke21: Pipelines is now generally available! Huge congratulations to the team and all who have supported reaching this milestone… 3 weeks ago
- New blog post : Call Dataverse actions directly in power-fx rajeevpentyala.com/2023/03/01/ste… 3 weeks ago
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- [Experimental Feature] Call Dataverse actions directly in Power Fx
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- God Mode - Level Up - Dynamics 365 Chrome Extension
- [Step by Step] Power Apps | Show pop ups in Canvas App
- Associate/Disassociate plugin messages in CRM
- Set “Created On”,” Created By”, “Modified On”, “Modified By” fields using SDK/Data Import/Plug-in – Dynamics 365
- [Step by Step] Connecting to Azure SQL Server using OLEDB Connection from SSIS
- [Code Snippet] Custom Workflow Activity with Input and Output Params
- C# - SQL - Bulk Insert records from Data Table and CSV
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.