2017-03-03 5 views
0

CRM 2016에 대한 첫 번째 사용자 지정 워크 플로와 막혔습니다. 동일한 이벤트에 대해 특정 연락처에 대해 생성 된 모든 사례의 수를 검색하려고합니다. 카운트를 출력 변수 (매개 변수)에 넣습니다. 내 코드는 다음과 같습니다.하지만 진행 방법을 모르겠습니다.특정 이벤트에 대해 주어진 연락처에 대한 모든 사례 검색

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Microsoft.Xrm.Sdk; 
using System.Activities; 
using Microsoft.Xrm.Sdk.Query; 
using Microsoft.Xrm.Sdk.Workflow; 
using System.Runtime.Serialization; 
using System.Net; 
using System.Net.Http; 
using System.Net.Http.Headers; 

namespace CRM.Workflows 
{ 
    public class Workflow_CheckExistingCase : CodeActivity 
    { 
     #region 
     [Input("ApplicantID")] 
     [ReferenceTarget("contact")] 
     public InArgument<EntityReference> ApplicantID { get; set; } 

     [Input("eventID")] 
     [ReferenceTarget("custom_event")] 
     public InArgument<EntityReference> eventID { get; set; } 

     [Output("Result")] 
     public OutArgument<bool> Result { get; set; } 
     #endregion 

     protected override void Execute(CodeActivityContext executionContext) 
     { 

      var context = executionContext.GetExtension<IWorkflowContext>(); 
      var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>(); 
      ITracingService tracingService = executionContext.GetExtension<ITracingService>(); 
      var service = serviceFactory.CreateOrganizationService(context.UserId); 

      try 
      { 
       EntityReference Applicant_ID = ApplicantID.Get<EntityReference>(executionContext); 
       EntityReference event_ID = eventID.Get<EntityReference>(executionContext); 

       var Did = event_ID.Id; 
       var Aid = Applicant_ID.Id; 

      } 

      catch (Exception ex) 
      { 
       tracingService.Trace("Error was created in the workflow:{0}", ex.Message); 
       Result.Set(executionContext, "Fail"); 
       //throw new InvalidPluginExecutionException(ex.Message); 
      } 
     } 

    } 

} 

위의 코드는 신청자 ID와 이벤트 ID를 검색하는 데 도움이됩니다. 그러나 해당 신청자와 해당 사건에 대해 얼마나 많은 사례가 있는지 확인하고 싶습니다. 이 문제를 어떻게 해결해야합니까?

답변

0

사용자 지정 워크 플로 작업에서 개수를 반환하려면 OutArgument<bool> ResultOutArgument<int> Result으로 변경하십시오.

사례 수를 얻는 가장 효율적인 방법은 FetchXml 쿼리를 사용하는 것입니다. 예를 들어 StackOverflow을 참조하십시오. CRM 웹 인터페이스에서 고급 찾기를 사용하여 필요한 쿼리를 만들고 다운로드 할 수 있습니다.

또 다른 방법은 QueryExpression 쿼리를 사용하고 반환되는 레코드 수를 계산하는 것입니다.

결과를 OutArgument<int>에 지정하십시오.