Forum Discussion

AngelaIp's avatar
AngelaIp
Ideator I
9 months ago

Is there an "in" operator in the Aras REST API?

Hi community,

Is there a way to optimize the following REST request that gets a number of specific items?

https: //   arasmagiccastle.com/test/server/odata/MagicItemType  ?$  filter=serial_number eq '9879' or serial_number eq '678' or serial_number eq '643' or serial_number eq '123' or serial_number eq '234'........

Problems:
1. The number of requested items isn´t fixed, so the query can get super long
2. I don´t like it (solid argument, don´t question it! [emoticon:33306c418930400bac28808410f8ac8b])

What I would love to have:
https://beautifulplm.com/test/server/odata/MagicItemType?$filter=serial_number in ('9879','678','643','123','234').

Good alternative:
Another option would be to use a POST operation with @aras.action=get. This would allow us to use the filter condition inside the body. But Innovator doesn´t seem to support this variant yet. 

Browsers support URLs with a few thousand characters. The long query isn´t a problem right now. But I wonder if there is a more elegant solution to write requests like this? Thanks for any hint!

@Aras: If you need more ideas for REST...Here you go! :)

3 Replies

  • Hi Angela,

    There is an "in" operator that you can see a use case of at the end of this blog. This example is for querying on collections of items, though I'm pretty sure it would be possible for an array of strings like you're proposing. I still need to test this myself (still getting my test instances set up), but I believe the syntax would be something like the example below:

    https://beautifulplm.com/test/server/odata/MagicItemType?$filter=in(serial_number,('9879','678','643','123','234')).

    • AngelaIp's avatar
      AngelaIp
      Ideator I

      Indeed! There is an IN operator! It´s even mentioned in the latest REST API guide. See "Extended condition in".

      But I am not sure if it´s really designed for my use case. Your example unfortunately didn´t work. 
      "IN" seems to be used to get additional information from linked item properties. Useful, but different use case. 

      The IN operator needs some additional arguments. I did some testing. Something like this works technically:

      https:// ; xxx /  yyy /server/odata/MyItemType?$select=serial_number,bpl_psid&$filter=in(id,$root/MyItemType($select=id;$filter=serial_number eq '123' or serial_number eq '456' ),id)

      @All: My variant is just a test and not supposed to be a role model example of how to use the IN condition! Please check Chris' mentioned blog article and the official REST API guide for examples! Right now this query does the same than my original sample above, just with an additional layer of complexity. Note that I use the same repeating structure to create the OR condition!

       christopher_gillis You don't have to put much work into this! The original variant works perfectly. Note that I love to over-optimize trivial tasks. Daan can confirm that. [emoticon:c4563cd7d5574777a71c318021cbbcc8]

      If there is an alternative option, I would be happy to use it. But the previous variants works perfectly already.