Thursday 16 May 2019

Retrieve note from opportunity and associate with custom entity note in C#



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

Numbering Table Parent group and child group ssrs report

 Recently I have faced a scenario to numbering parent group and subgroup in the following formate 10 parentGroupRow1    10.1 childGroupRow1 ...