cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

How to populate the "query" field when testing Services that have a querying ability

lorenmc
1-Visitor

How to populate the "query" field when testing Services that have a querying ability

Hi,

I'm trying to test the the QueryStreamEntriesWithData service by selecting the "Test" button beside the service.  One of the fields that needs to be populated is "query".  So if I want to filter the data such that I see only the stream entries that has one of the columns equal a specific value, what do I enter into this field?

Thanks,

Loren

6 REPLIES 6
adam11
7-Bedrock
(To:lorenmc)

Hi Loren,

We have documentation available that will help you create a query to supply to QueryStreamEntriesWithData() (see section

3.07.02.01 Query Parameter for Query Services of the Wiki

). Testing a Service which takes a query parameter is probably not something you want to attempt from Composer. The easiest way to test it would be to create a Mashup with a Grid and Data Filter widget. The Data Filter widget creates a query that you can then supply to QueryStreamEntriesWithData(). Alternately, you could create a wrapper Service that defines a query and calls QueryStreamEntriesWithData().


In 5.0, there is functionality to help you easily construct a query without needing to consult the Wiki.


Thanks,

Adam











lorenmc
1-Visitor
(To:lorenmc)

Hi Adam,

Thanks for the reply.  I'm trying the second method you suggested but I'm having some trouble.  Below is my code.  I want all the entries in the stream that have the value of 1 in the "sensorNo" column.  However, I can't this service to return anything back to me.  I don't get any errors but my results are empty.  Any idea what I'm doing wrong?


var query1 = {

    

    filters: {

        

        type: "EQ", 

        fieldName: "sensorNo", value: "1"

    }

};


var params = {

tags: undefined /* TAGS /,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>oldestFirst: undefined / BOOLEAN /,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>startDate: undefined / DATETIME /,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>source: undefined / STRING /,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>query: query1 / QUERY /,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>endDate: undefined / DATETIME /,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sourceTags: undefined / TAGS /,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>maxItems: undefined / NUMBER */

};


// result: INFOTABLE

var result = Things["ParsedSensorDataStream"].QueryStreamEntriesWithData(params);



adam11
7-Bedrock
(To:lorenmc)

I assume sensorNo is of type NUMBER? If so, you'll need to remove the quotation marks around 1.


– Adam



jasong
12-Amethyst
(To:lorenmc)

For others in the future, two common problem I have with queries, one of them hopefully fixed in 5.0 with the new builder, are:


1. Copying filter code from the Wiki doesn't work. I think the brackets are different than your keyboard brackets, and while Javascript does ok with them, query processing does not like it.


2. Getting null results back when you are SURE that data exists: look at Visibility and Security on the Entities that you are querying.



Now that we are at version 6.x of the Composer,  is there a way to populate the query field when testing the QueryStreamEntriesWithData service as Loren originally requested?

Simply want to filter the query on  Id = 1

An example will be great if anyone has one.

Thanks,

Error message: "Invalid QUERY value. Please make sure it's a valid JSON string"

No matter what is placed in the "query" box of the QueryStreamEntriesWithData - Test Service.

Guidance and example appreciated.

Thanks,

Announcements


Top Tags