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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Get a Particular Infotable Field with a Service

vieirac1
10-Marble

Get a Particular Infotable Field with a Service

Hi Team,

 

I have the below service, calling QueryImplementingThingswithData that returns to me an Infotable with several fields,

 

However, I only want my service to return a particular field from this infotable, please, how to do it?

 

 

// result: INFOTABLE dataShape: "RootEntityList"
var retorno = ThingTemplates["MyTemplate"].QueryImplementingThingsWithData({
maxItems: undefined /* NUMBER */,
nameMask: undefined /* STRING */,
query: myquery /* QUERY */,
tags: undefined /* TAGS */
});

 

//this query will return an infotable with many fields, how do I return only 1 of these fields?


var result = //I just need 1 field from the infotable above

ACCEPTED SOLUTION

Accepted Solutions
Radu
15-Moonstone
(To:vieirac1)

That's what Distinct does, it removes duplicates and returns only one column.

 

If you want to keep the duplicates, you'd have to use the CreateInfoTable service to create a new infotable, add the desired field to it through AddField, and then add rows to the newly created infotable using AddRow and iterating through the bigger infotable.

 

You can access column values like this: info.rows[x].columnName.

View solution in original post

5 REPLIES 5
Radu
15-Moonstone
(To:vieirac1)

Hi,

 

In the Query service, you can define maxItems as 1, and it will only return one result.

vieirac1
10-Marble
(To:Radu)

Actually, i need to return all rows, but only a particular field for these set of rows
Radu
15-Moonstone
(To:vieirac1)

You can use the Distinct() method of the InfoTableFunctions for that. Search for "Distinct" in Code Snippets.

vieirac1
10-Marble
(To:Radu)

Tks a lot, will test and let you know

I thought distinct would remove rows with similar values
Radu
15-Moonstone
(To:vieirac1)

That's what Distinct does, it removes duplicates and returns only one column.

 

If you want to keep the duplicates, you'd have to use the CreateInfoTable service to create a new infotable, add the desired field to it through AddField, and then add rows to the newly created infotable using AddRow and iterating through the bigger infotable.

 

You can access column values like this: info.rows[x].columnName.

Announcements


Top Tags