【问题标题】:Get the list of notes获取笔记列表
【发布时间】:2016-07-07 13:32:06
【问题描述】:

如何获取与当前实体关联的所有笔记的 guid 列表(或例如集合)?

我知道它以某种方式与 service.Retreive(...) 相关联,但无法生成工作代码。

附上1:

public void Execute(IServiceProvider serviceProvider)
{
    Entity entity = null;

    var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    if (entity.Contains("new_parentopportunity"))
    {
        try
        {
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factory.CreateOrganizationService(context.UserId);

            Guid projectGuid = entity.Id;
            Guid oppGuid = ((EntityReference)entity["new_parentopportunity"]).Id;

            for (int i = 0; i < 100; i++) //Instead of 100, I'll place obtained collection.Length
            {
                Entity opp = service.Retrieve("", oppGuid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)); //RETREIVE ENTITY NOTE HERE
                var temop = CreateNoteAttachment(opp);
                service.Create(temp);
            }

        }
        catch (Exception ex)
        {
            throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
        }
    }
}

private Entity CreateNoteAttachment(Entity oppNote)
{
    //some code here
}

更新 1:

我也把它写在查询中,你能看看这个,是否一切都好? PasteBin

【问题讨论】:

  • 你有一些代码要分享吗?你尝试过什么,你哪里出错了?
  • @Marcus,是的,我已经发布了代码。我不明白我应该投入什么 service.Retreive() 另外,我已经看到了一种通过构造查询来做到这一点的方法
  • 该插件是将所有笔记从一个实体复制到另一个实体。

标签: c# plugins dynamics-crm-2011


【解决方案1】:

查询相关笔记的两种方式:

早期绑定:

 var  notes =
                service.AnnotationSet.Where(annotation => annotation.Opportunity_Annotation.Id == entity.Id)
                    .Select(annotation => annotation.Id)
                    .ToList();

FetchXml:

  var fetchXml = string.Format("<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                                    "<entity name='annotation'>" +
                                    "<attribute name='annotationid' />" +
                                    "<filter type='and'>"+
                                    "<condition attribute='objectid' operator='eq' value='{0}'/>"+
                                    "</filter>"+
                                    "</entity>" +
                                    "</fetch>", entity.Id);

            var response = service.RetrieveMultiple(new FetchExpression(fetchXml));
            var notes = response.Entities;

【讨论】:

  • 谢谢,这太棒了!但是有什么方法可以减少资源密集度呢? (我想是 xml 的,但我无法证明这一点)
猜你喜欢
  • 2017-10-31
  • 2017-09-01
  • 2019-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多