Filtering data requests

2 posts, 0 answers
  1. Kevin
    Kevin avatar
    16 posts
    Member since:
    Oct 2015

    Posted 01 Mar 2016 Link to this post

    i am trying to download data from the back-end services with a number of conditions that must be satisfied.

    i achieved this in swift for the ios version of the app using a NSPredicate

    request.predicate = NSPredicate(
        format: "CreatedByName == %@ OR (To ==%@ AND CreatedByName == %@)",

    i need a similar solution for the javascript api. my problem is knowing hopw to combine the AND and OR. I have Tried:

    var query = new Everlive.Query();
            .eq('CreatedBy', customerName)
            .eq('To', to)


    But how do i add the or.


    It is a messing section of an app the admin can chat with any end user but the end user can only reply to the admin or or send messages to the admin so my query needs to reflect that in a chat stream. ie. is (created by admin AND is to userA ) OR (is created by userA)

  2. Martin
    Martin avatar
    103 posts

    Posted 02 Mar 2016 Link to this post

    Hello Diego,

    With 'and' and 'or' querying methods you create complex condition. The complex conditions are terminated with the done() method. You can think of calling and() .... done() as the brackets "()" in mathematics - anything that is between them will be evaluated first.

    The example in question -> "(created by admin AND is to userA ) OR (is created by userA)" will look like:

    var query = new Everlive.Query();
                .eq('CreatedBy', admin)
                .eq('To', userA)
            .eq('CreatedBy', userA)

    The last done() can be omitted as there are no following conditions (but this way it looks clearer).

    Let me know if this has worked for you.

    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
Back to Top