不要在 Dynamics 365 Web API 数据检索查询中返回重复项

我正在使用以下查询参数通过 Dynamics 365 Web API (PHP) 检索所有活动成员资格记录。


$params = array(

    "$select" => "member_number,statuscode,statecode",

    "$filter" => "statecode eq 1"

);

这将返回所有活动成员资格记录(状态代码 1)。但是,由于特定成员可能拥有即将到期的成员资格和最近更新的成员资格(等等),单个实体可能会返回多个活动记录,从而使我的结果变得臃肿。我只需要知道一个实体是否处于活动状态一次,而不是六次。


有没有办法排除重复记录,以便我只收到每个活动会员记录的一个实例?我正在寻找与DISTINCT在 SQL 查询中使用等效的 Dynamics 365 Web API 。


POPMUISE
浏览 243回答 3
3回答

慕姐4208626

虽然我不记得 WebAPI 有一个 Distinct 运算符,但FetchXML 有.并且,您可以通过 API 运行 FetchXML例如,没有Distinct:https://myOrg.crm.dynamics.com/api/data/v9.0/contacts?fetchXml=<fetch mapping='logical'>&nbsp; <entity name='contact'>&nbsp; &nbsp; <attribute name='fullname' />&nbsp; &nbsp; <filter>&nbsp; &nbsp; &nbsp; &nbsp; <condition attribute='fullname' operator='eq' value='Nick Saban'/>&nbsp; &nbsp; </filter>&nbsp; </entity></fetch>返回:{&nbsp; &nbsp;"@odata.context":"https://myOrg.crm.dynamics.com/api/data/v9.0/$metadata#contacts(fullname,contactid)",&nbsp; &nbsp;"value":[&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"@odata.etag":"W/\"175969918\"",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"fullname":"NICK SABAN",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"contactid":"ca338867-8831-e511-8103-c4346bac6974"&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"@odata.etag":"W/\"187905023\"",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"fullname":"NICK SABAN",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"contactid":"fff12a11-ef85-e511-810a-fc15b4281ce0"&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;]}与Distinct:https://myOrg.crm.dynamics.com/api/data/v9.0/contacts?fetchXml=<fetch mapping='logical' distinct='true'>&nbsp; <entity name='contact'>&nbsp; &nbsp; <attribute name='fullname' />&nbsp; &nbsp; <filter>&nbsp; &nbsp; &nbsp; &nbsp; <condition attribute='fullname' operator='eq' value='Nick Saban'/>&nbsp; &nbsp; </filter>&nbsp; </entity></fetch>返回:{&nbsp; &nbsp;"@odata.context":"https://myOrg.crm.dynamics.com/api/data/v9.0/$metadata#contacts(fullname)",&nbsp; &nbsp;"value":[&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"fullname":"NICK SABAN"&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;]}

动漫人物

我不是来自 php 背景,但我会尝试。Distinct只能在 FetchXML 查询中使用,fetchxml 可以与 web api 一起使用。我可以找到以下示例 - AlexaCRM 工具包的在线参考。$fetchXML = <<<FETCHXML<fetch mapping="logical" distinct="true">&nbsp;&nbsp; &nbsp; <entity name="new_membership">&nbsp; &nbsp; &nbsp; &nbsp; <attribute name="member_number" />&nbsp;&nbsp; &nbsp; </entity></fetch>FETCHXML;$fetchExpression = new \AlexaCRM\Xrm\Query\FetchExpression( $fetchXML );$collection = $client->RetrieveMultiple( $fetchExpression );

千万里不及你

由于 Dynamics 支持 ODATA 4.0,您可以通过以下方式使用 $apply 进行查询:$params = array(&nbsp; &nbsp; "$apply" => "groupby((member_number))",&nbsp; &nbsp; "$filter" => "statecode eq 1");此查询将返回不同的 JSON,但在您的实体中包含不同的“member_numbers”集合。希望能帮助到你。这个答案来自这个问题。请查看详细信息。
打开App,查看更多内容
随时随地看视频慕课网APP