使用自定义工作流活动C#中的自定义字段检索CRM 4实体

时间:2015-02-10 10:58:22

标签: crm

我试图检索与机会相关的所有电话,状态码不等于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异常或"服务器无法继续执行请求"在调试时。

1 个答案:

答案 0 :(得分:0)

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

RetrieveMultipleResponse retrieve = null;

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