【问题标题】:Retrieve all Cases for given contact for a particular event检索特定事件的给定联系人的所有案例
【发布时间】:2017-03-03 00:49:36
【问题描述】:

我的第一个 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。但是我想检查该申请人以及在该事件中存在多少案例。我该怎么办?

【问题讨论】:

    标签: c# dynamics-crm workflow dynamics-crm-online


    【解决方案1】:

    您希望自定义工作流活动返回计数,因此将 OutArgument&lt;bool&gt; Result 更改为 OutArgument&lt;int&gt; Result

    获取案例数量的最有效方法是使用 FetchXml 查询。有关示例,请参阅StackOverflow。您可以使用 CRM Web 界面中的高级查找来创建和下载您需要的查询。

    另一种方法是使用QueryExpression 查询并计算返回的记录数。

    将计数分配给OutArgument&lt;int&gt; Result。

    【讨论】:

      猜你喜欢
      • 2018-10-29
      • 2012-10-18
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      • 2023-03-14
      • 1970-01-01
      • 2010-11-11
      相关资源
      最近更新 更多