Dynamics crm remove the repeated data while fetching via api

心已入冬 提交于 2020-06-17 15:51:08

问题


Trying to retrieve all state under one particular country.

URL:

api/data/v9.1/leadaddresses?$select=stateorprovince&$filter=stateorprovince ne  null and country eq 'US'&$count=true&$orderby=stateorprovince

Problem here is it returns data like this

"value": [
  {
"@odata.etag": "W/"166729382"",
"stateorprovince": "AK",
"leadaddressid": "691de670-aa45-426b-8fee-00b3a7f7e469"
},
  {
"@odata.etag": "W/"166729369"",
"stateorprovince": "AK",
"leadaddressid": "12db5897-dc53-44ae-b4aa-03c5486ad6ac"
},
  {
"@odata.etag": "W/"166729416"",
"stateorprovince": "AK",
"leadaddressid": "f64ccf06-fa67-421a-aa5f-0469302be1c2"
},
  {
"@odata.etag": "W/"166729206"",
"stateorprovince": "AK",
"leadaddressid": "b1f9ce4a-a06b-4d7d-befc-04bea0d41a4e"
},
  {
"@odata.etag": "W/"166729323"",
"stateorprovince": "AK",
"leadaddressid": "a4b9ff56-2d24-4957-b09b-04ef6ce56304"
},

Any way to remove the repeated data.


回答1:


You have to use fetchxml to get distinct values, that is the only option.

<fetch top="50" distinct="true" >
  <entity name="leadaddress" >
    <attribute name="stateorprovince" />
    <filter type="and" >
      <condition attribute="stateorprovince" operator="not-null" />
    </filter>
  </entity>
</fetch>

You can use web api endpoint and use the above fetchxml like below:

https://crmdev.crm.dynamics.com/api/data/v9.1/leadaddresses?fetchXml=<fetch top="50" distinct="true" >   <entity name="leadaddress" >     <attribute name="stateorprovince" />     <filter type="and" >       <condition attribute="stateorprovince" operator="not-null" />     </filter>   </entity> </fetch>


来源:https://stackoverflow.com/questions/62259166/dynamics-crm-remove-the-repeated-data-while-fetching-via-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!