Introduction:
In this blog we will see how to move Notes from One Entity to Another
Implementation Steps:
Consider when ever I Qualify a Lead to Contact, I need to Move the Respective Lead(Notes/Attachment) from Lead to Contact.
Let's see how can we do that.
Create a Plugin
string getNotes = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='annotation'>
<all-attributes />
<order attribute='subject' descending='false' />
<link-entity name='lead' from='leadid' to='objectid' link-type='inner' alias='aa'>
<filter type='and'>
<condition attribute='leadid' operator='eq' value='{objectid}' />
</filter>
</link-entity>
</entity>
</fetch>";
getNotes = getNotes.Replace("{objectid}", "LEADGUID");
EntityCollection collectNotes = service.RetrieveMultiple(new FetchExpression(getNotes));
foreach (var loopColelctNotes in collectNotes.Entities)
{
Entity _annotation = new Entity("annotation");
_annotation.Attributes["objectid"] = new EntityReference("contact", getContactDetails.Id);
_annotation.Attributes["objecttypecode"] = "contact";
if (loopColelctNotes.Attributes.Contains("subject"))
{
_annotation.Attributes["subject"] = loopColelctNotes.Attributes["subject"];
}
if (loopColelctNotes.Attributes.Contains("documentbody"))
{
_annotation.Attributes["documentbody"] = loopColelctNotes.Attributes["documentbody"];
}
if (loopColelctNotes.Attributes.Contains("mimetype"))
{
_annotation.Attributes["mimetype"] = loopColelctNotes.Attributes["mimetype"];
}
if (loopColelctNotes.Attributes.Contains("notetext"))
{
_annotation.Attributes["notetext"] = loopColelctNotes.Attributes["notetext"];
}
if (loopColelctNotes.Attributes.Contains("filename"))
{
_annotation.Attributes["filename"] = loopColelctNotes.Attributes["filename"];
}
service.Create(_annotation);
}
Trigger the above code on Create of an Entity in Async Operation.
No comments:
Post a Comment