簡體   English   中英

在Dynamics CRM中將RetrieveMultiple與FetchXML一起使用時,出現“ System.ServiceModel.FaultException`1”

[英]'System.ServiceModel.FaultException`1' when using RetrieveMultiple with FetchXML in Dynamics CRM

嘗試從FetchXML查詢獲取結果時,始終出現上述錯誤。 任何幫助,將不勝感激。 該錯誤總是在行上發生:

    EntityCollection GetAllOpenActivitiesXML_result = service.RetrieveMultiple(fetched1);

這是其余的代碼:

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

Entity opp = new Entity("opportunity");
opp.Id = context.PrimaryEntityId;

string GetAllOpenActivitiesXML = @"
<fetch distinct='false' mapping='logical' aggregate='true'> 
<entity name='activitypointer'>
     <attribute name='activityid' aggregate='count' alias='activityid'/>
          <filter type='and'>
                 <condition attribute='statecode' operator='eq' value='0' /> 
          </filter>
     <link-entity name='opportunity' from='opportunityid' to='regardingobjectid'>
          <filter type='and'>
                 <condition attribute='name' operator='eq' value='MyOpportunity' />
          </filter>
     </link-entity> 
 </entity> 
 </fetch>";

    try {
         FetchExpression fetched1 = new FetchExpression(GetAllOpenActivitiesXML);
        EntityCollection GetAllOpenActivitiesXML_result = service.RetrieveMultiple(fetched1);

             foreach (var c in GetAllOpenActivitiesXML_result.Entities)
             { 
              Int32 totalOpenActivities = (Int32)((AliasedValue)c["activityid"]).Value;
              opp["new_openactivities"] = totalOpenActivities;
              }
        }
    catch { 
           opp["new_openactivities"] = 0; 
          }

 service.Update(opp);

造成此問題的原因是,您使用字段名稱作為別名,因此,如果更改別名,它將開始起作用:

<fetch distinct="false" mapping="logical" aggregate="true" >
  <entity name="activitypointer" >
    <attribute name="activityid" alias="activityid_count" aggregate="count" />
    <filter type="and" >
      <condition attribute="statecode" operator="eq" value="0" />
    </filter>
    <link-entity name="opportunity" from="opportunityid" to="regardingobjectid" >
      <filter type="and" >
        <condition attribute="name" operator="eq" value="MyOpportunity" />
      </filter>
    </link-entity>
  </entity>
</fetch>

另外,我不知道您使用的是哪個CRM版本,但是我很確定可以將該插件替換為匯總字段,因此請嘗試一下!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM