2016-07-07 5 views
0

現在のエンティティに関連付けられているすべてのノートのガイドのリスト(またはコレクションなど)を取得するにはどうすればよいですか?ノートのリストを取得

私はそれが何らかの形で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:

私はまた、あなたがwhethereすべて罰金が、これを見ることができ、クエリでそれを書くのか?アーリーバインド

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

FetchXml: PasteBin

+0

あなたが共有するためのいくつかのコードを持っていますか?あなたは何を試していますか?どこに間違っていますか? – Marcus

+0

@Marcus、はい私はコードを投稿しました。私は何を私がservice.Retreiveに入れるべきか分からない。 また、私はクエリーを構築することによってこれを行う方法を見た。 –

+0

プラグインは、あるエンティティから別のエンティティへのすべてのメモをコピーすることに関するものです。 –

答えて

1

つの方法は、関連のノートを照会する

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; 
+0

ありがとう、これは素晴らしいです! しかし、リソースの消費量はどのように少なくなりますか? (私はXMLのものと思うが、これを証明することはできない) –

関連する問題