private void RetrieveRelatedNoteFromOppAndAttachWithBid(IOrganizationService orgService, Guid oppId, Guid bidId)
{
try
{
string fetchxml = @"<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>
<entity name='annotation'>
<attribute name='subject'/>
<attribute name='notetext'/>
<attribute name='filename'/>
<attribute name='annotationid'/>
<attribute name='isdocument'/>
<attribute name='filesize'/>
<attribute name='mimetype' />
<attribute name='documentbody'/>
<order descending='true' attribute='createdon'/>
<filter type='and'>
<condition attribute='objectid' operator='eq' value='" + oppId + @"'/>
</filter>
</entity>
</fetch>";
EntityCollection results = orgService.RetrieveMultiple(new FetchExpression(fetchxml));
if (results.Entities.Count > 0)
{
Entity noteOpp = results.Entities[0];
Entity noteBid = new Entity("annotation");
noteBid["objectid"] = new EntityReference("ab_bid", bidId);
noteBid["objecttypecode"] = "ab_bid";
noteBid["subject"] = noteOpp["subject"];
noteBid["documentbody"] = noteOpp["documentbody"];
noteBid["mimetype"] = noteOpp["mimetype"];
noteBid["filename"] = noteOpp["filename"];
orgService.Create(noteBid);
orgService.Delete(noteOpp.LogicalName, noteOpp.Id);
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
No comments:
Post a Comment