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

Powerful Things you can do with DeriveFields

Highlighted
Turquoise

Powerful Things you can do with DeriveFields

Thingworx provides a library of InfoTable functions, one of the most powerful ones being DeriveFields (besides that I use Aggregate and Query a lot and ... getRowCount)

DeriveFields can generate additional columns to your InfoTable and fill that with values that can be derived from ... nearly anything! Hard coded, based on a Service you call, based on a Property Value, based on other values within the InfoTable you are adding the column to.

Just remember for this Service (as well as Aggregate), no spaces between different column definitions and use a , (comma) as separator.

Here are some two powerful examples:

//Calling another function using DeriveFields

//Note that the value thingTemplate is the actual value in the row of column thingTemplate!

var params = {

  types: "STRING" /* STRING */,

  t: AllItems /* INFOTABLE */,

  columns: "BaseTemplate" /* STRING */,

    expressions: "Things['PTC.RemoteMonitoring.GeneralServices'].RetrieveBaseTemplate({ThingTemplateName:thingTemplate})" /* STRING */

};

// result: INFOTABLE

var AllItemsWithBase = Resources["InfoTableFunctions"].DeriveFields(params);

//Getting values from other Properties

//to in this case is the value of the row in the column to

//Note the use of , and no spaces

//NOTE: You can make this even more generic with something like Things[to][propName]

var params = {

    types: "NUMBER,STRING,STRING,LOCATION" /* STRING */,

    t: AllAssets /* INFOTABLE */,

    columns: "Status,StatusLabel,Description,AssetLocation" /* STRING */,

    expressions: "Things[to].Status,Things[to].StatusLabel,Things[to].description,Things[to].AssetLocation" /* STRING */

};

// result: INFOTABLE

var AllAssetsWithStatus = Resources["InfoTableFunctions"].DeriveFields(params);

4 REPLIES 4

Re: Powerful Things you can do with DeriveFields

Hi Pai,

Can we use in the DeriveFields an expression making reference to the previous row?

Re: Powerful Things you can do with DeriveFields

Since I don't know exactly how DeriveFields works, I'm not sure.

Probably best to do a regular loop

Re: Powerful Things you can do with DeriveFields

Hi Vlad,

I don't think so, anyway, it's always tricky to reference previous row ( for instance when you are on row[0] you don't have previous row... )

Carles.

Re: Powerful Things you can do with DeriveFields

Is it possible to add as row number as derived field in the infotable??

 

Thanks,

Varathan