【问题标题】:Retrieving CRM 4 entities with custom fields in custom workflow activity C#在自定义工作流活动 C# 中检索具有自定义字段的 CRM 4 实体
【发布时间】:2015-02-10 10:58:21
【问题描述】:

我正在尝试检索与机会相关的所有电话,其中状态码不等于 1。尝试了 QueryByAttribute、QueryExpression 和 RetrieveMultipleRequest,但仍然没有解决方案。
这是我写的一些代码。

        IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
        IWorkflowContext context = contextService.Context;
        ICrmService crmService = context.CreateCrmService(true);
        if (crmService != null)
        {
            QueryByAttribute query = new Microsoft.Crm.Sdk.Query.QueryByAttribute();
            query.ColumnSet = new Microsoft.Crm.Sdk.Query.AllColumns();
            query.EntityName = EntityName.phonecall.ToString();
            query.Attributes = new string[] { "regardingobjectid" };
            query.Values = new string[] { context.PrimaryEntityId.ToString() };
            RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
            retrieve.Query = query;
            retrieve.ReturnDynamicEntities = true;
            RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)crmService.Execute(retrieve);  
        }
        return ActivityExecutionStatus.Closed;
    }

QueryExpression 几乎相同

QueryExpression phCallsQuery = new QueryExpression();
ColumnSet cols = new ColumnSet(new string[] { "activityid", "regardingobjectid" });
phCallsQuery.EntityName = EntityName.phonecall.ToString();
phCallsQuery.ColumnSet = cols;
phCallsQuery.Criteria = new FilterExpression();
phCallsQuery.Criteria.FilterOperator = LogicalOperator.And;
phCallsQuery.Criteria.AddCondition("statuscode", ConditionOperator.NotEqual, "1");
phCallsQuery.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, context.PrimaryEntityId.ToString();

在调试时,我总是收到诸如 Soap 异常或“服务器无法继续请求”之类的信息。

【问题讨论】:

    标签: crm


    【解决方案1】:

    要获取异常详细信息,请尝试使用以下代码:

    RetrieveMultipleResponse 已检索 = null;

    try
    { 
        retrieved = (RetrieveMultipleResponse)crmService.Execute(retrieve);
    }
    catch(SoapException se)
    {
        throw new Exception(se.Detail.InnerXml);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-27
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      相关资源
      最近更新 更多