I want to delete Notes(annotation) and Attachment from account entity using C# web service.
Help me
*This post is locked for comments
I want to delete Notes(annotation) and Attachment from account entity using C# web service.
Help me
*This post is locked for comments
Any way to delete only the Attachment and keep the Notes instead?
Don't want to delete the Note (attachment) itself
//Query to get notes with attachment associated with an entity
QueryExpression records = new QueryExpression{EntityName = "annotation",ColumnSet = new ColumnSet("subject","filename","notetext","documentbody"), Criteria = new FilterExpression { Conditions = { new ConditionExpression { AttributeName = "objectid", Operator = ConditionOperator.Equal, Values = {entityId} //Guid Id of account entity record } ,//The below condition is for getting notes with attachments only.Exclude the below condition to retreive all notes. new ConditionExpression { AttributeName = "isdocument", Operator = ConditionOperator.Equal, Values = {true} } } } };
//Retrieve all notes in entitycollection EntityCollection notes = service.RetrieveMultiple(records);
//If notes records found if(notes.Entities.Count > 0) {
//Loop through the entitycollection foreach (Entity note in notes.Entities) {
// Delete the note record service.Delete("annotation",note.Id); } }
Hi DMat,
Refer the below MSDN sample to perform CRUD on Annotation-
msdn.microsoft.com/.../gg328429.aspx
Hope this helps.
Hello,
Can take a help from below code:
private void DeleteNoteAttachments(Guid entityId)
{
EntityCollection results = null;
QueryExpression _noteattachmentQuery = new
QueryExpression
{
EntityName = “annotation”,
ColumnSet = new ColumnSet("subject","filename","notetext","documentbody"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "objectid",
Operator = ConditionOperator.Equal,
Values = {entityId}
},
new ConditionExpression
{
AttributeName = "isdocument",
Operator = ConditionOperator.Equal,
Values = {true}
}
}
}
};
using (var service = new OrganizationService("CrmConnection"))
{
results = service.RetrieveMultiple(_noteattachmentQuery);
if(results.Entities.Count > 0)
{
foreach (Entity act in ec.Entities){
service.Delete(act.Id);
}
}
}
}
Mark this an answer, If it helps.
Cheers
Arpit
https://arpitmscrmhunt.blogspot.in
Hello,
here you go!
QueryExpression query = new QueryExpression("account"); EntityCollection retrieveedxpan = service.RetrieveMultiple(query); if (retrieveedxpan.Entities.Count == 0) { tracingService.Trace("nothing found"); } else { foreach (var entity in retrieveedxpan.Entities) { //Here you can remove the attachments
Kind Regards
Léon
hello,
Please use querybyexpression to retrieve the attachments from account. Once you have it use foreach loop and do a service.deleted(attachmentid).
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156