1
特定のアカウント(テスト機能)に関連するすべてのコントラクトを取得できるクエリ式を作成しています。私が探しているものと一致するレコードが1つありますが、クエリは結果を返しません。問題はlinkEntity自体の中にあると思っていますが、わかりません。fm xmlからのcrmクエリ式
fetchxmlでguidを使用してqueryexpressionを作成してから結果が返ってきて以来、エラーは発生しなくなりました。コメントから
<?xml version="1.0"?>
<fetch distinct="true" mapping="logical" output-format="xml-platform" version="1.0">
<entity name="contract">
<attribute name="title"/>
<attribute name="statecode"/>
<attribute name="modifiedon"/>
<attribute name="modifiedby"/>
<attribute name="customerid"/>
<attribute name="createdon"/>
<attribute name="createdby"/>
<attribute name="hc_contracttype"/>
<attribute name="hc_contractsubtype"/>
<attribute name="activeon"/>
<attribute name="hc_contractlevel"/>
<attribute name="expireson"/>
<attribute name="hc_contractaccount"/>
<attribute name="hc_businessunit"/>
<attribute name="contractid"/>
<order descending="false" attribute="title"/>
<link-entity name="hc_account_contract" intersect="true" visible="false" to="contractid" from="contractid">
<link-entity name="account" to="accountid" from="accountid" alias="ab">
<filter type="and">
<condition attribute="name" value="Test Facility" operator="eq"/>
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
LinkEntity accountLink = new LinkEntity()
{
Columns = new ColumnSet(true),
LinkFromEntityName = "hc_account_contract",
LinkFromAttributeName = "contractid",
LinkToEntityName = "account",
LinkToAttributeName = "accountid",
EntityAlias = "ab"
};
accountLink.LinkCriteria.AddCondition("name", ConditionOperator.Equal, "Test Facility");
QueryExpression exp = new QueryExpression("contract");
exp.LinkEntities.Add(accountLink);
exp.ColumnSet = new ColumnSet(true);
EntityCollection results = _service.RetrieveMultiple(exp);
Console.WriteLine("There are " + results.Entities.Count);
foreach (Entity r in results.Entities)
{
Console.WriteLine(r.GetAttributeValue<string>("title"));
}
実際に正常なコードが動作しますが、なんらかの理由でその特定のアカウントで作業していないだけです。 – amberl
名前ではなく名前でフィルタリングしよう – ASpirin