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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Selecting one or more specific fields in query

jensc
17-Peridot

Selecting one or more specific fields in query

Hello Community,

 

I've been trying to figure out how to use the "select" key in the JSON query functionality of QueryStreamData...

 

me.QueryStreamData({
  //   oldestFirst: undefined /* BOOLEAN */,
  //   maxItems: undefined /* NUMBER {"defaultValue":500} */,
  //   sourceTags: undefined /* TAGS */,
  //   endDate: undefined /* DATETIME */,
  //   query: undefined /* QUERY */,
  //   source: undefined /* STRING */,
  //   startDate: undefined /* DATETIME */,
  //   tags: undefined /* TAGS */,
  // });

 

However I haven't had any luck...

There is no datashape returned for this service, and even if there was one, I'm not entirely sure I could get it to work.

 

I have do have a datashape for the stream of course, and I did try to use that using the following query:

"select": [
    {
        "dataShapeName": "MyDataShape",
        "fieldName": "FieldName"
    }
]

 But that didn't work either.

 

I also tried just querying everything from my stream and doing an infotable query:

let test = DataShapes["MyDataShape"].CreateValuesWithData({
    values: { values },
  });

  // Provide your filter using the format as described in the help topic "Query Parameter for Query Services"
  let query = {
    "select": [{
      "dataShapeName": "MyDataSHape",
      "fieldName": "FieldName",
    }],
  };

  let params = {
    t: test /* INFOTABLE */,
    query: query /* QUERY */,
  };

  result = Resources["InfoTableFunctions"].Query(params);

 

But this also didn't work... Anyone got any idea of what I am doing wrong?

Or that has done this with success before?

 

Any help would be highly appreciated!

 

Thanks,

Jens C.

ACCEPTED SOLUTION

Accepted Solutions
Rocko
18-Opal
(To:jensc)

Ah, Operator Advisor, I wondered where you got the "select" idea from. Yeah, that's OA only, different implementation since the OA entities use different templates/classes. RemoveField is probably the easiest solution.

View solution in original post

4 REPLIES 4
Rocko
18-Opal
(To:jensc)

There is no "select" field in the query there is only sorts and filters, as documented in the help topic "Query Parameter for Query Services" as well as in the QueryStreamData Service Info:"Query stream data (no stream entry details), along with filter and sort criteria".

You will get back rows according to the DataShape you assigned to the Stream,

jensc
17-Peridot
(To:Rocko)

Hello @Rocko,

 

Aha, so this only applies to OA?: Link 

 

And there is no other way of getting just one of the columns of a stream that is containing multiple columns?

I guess I'll have to write some service that removes them "manually" with the .RemoveField() function...

 

Thanks though!

Jens C.

Rocko
18-Opal
(To:jensc)

Ah, Operator Advisor, I wondered where you got the "select" idea from. Yeah, that's OA only, different implementation since the OA entities use different templates/classes. RemoveField is probably the easiest solution.

jensc
17-Peridot
(To:Rocko)

Hello @Rocko,

 

Yeah, I thought it would work with all "query" inputs.

In the end I went with looping over each field definition of the stream and removing it from the stream infotable if it wasn't the field name I wanted to keep.

 

Not sure how well it will scale, but shouldn't be an issue with the number of properties in our streams.

 

Thanks!

Jens C.

Announcements


Top Tags