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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

How to provide comma in derive fields expression

abhiramk
11-Garnet

How to provide comma in derive fields expression

Hello, 

I am having JSON property in Thing  which contains history of changes. I am trying to sort that JSON property and fetch the first entry. I am trying to fetch this using derive fields snippet but my expression is containing comma and thingworx is considering characters after comma as new expression. How to handle this? Tried using encoded characters, still it didn't work.

 

Is there a way to write function and call in derive fields expression?

 

-thanks,
Abhiram

6 REPLIES 6
PaiChung
22-Sapphire I
(To:abhiramk)

You can do something like "My expression part 1 " + "'special character to include'" + "My expression part 2"

@PaiChung Hello, Thank you for your reply.

 

I have  tried that still it didn't work, have a look below please:

 

var allAssets = ThingShapes["Factory.Assetshape"].QueryImplementingThingsWithData(params);

var params = {
types: "STRING" /* STRING */,
t: allAssets /* INFOTABLE */,
columns: "LastUpdate" /* STRING */,
expressions: "JSON.parse(Things[name].History).sort(function (a" + "','" + "b) {return b.Timestamp.localeCompare(a.Timestamp);})[0].Timestamp" /* STRING */
};
// result: INFOTABLE
result = Resources["InfoTableFunctions"].DeriveFields(params);

 

Any other way to handle this? 

Thanks!

PaiChung
22-Sapphire I
(To:abhiramk)

If ... you can do it all with just one value being passed in, you can call another service in your expression.

If I'm passing single expression it's working fine but if I combine with other expression it's not taking the name.

Working:
expressions: "Things['Factory.Generic'].GetAssetLastUpdate({thingName: name});" /* STRING */

Combined with other expression it's not working:

expressions: "BookValueDate.toISOString()ReplacementDate.toISOString(),Things['Factory.Generic'].GetAssetLastUpdate({thingName: name})" /* STRING */

 

 

PaiChung
22-Sapphire I
(To:abhiramk)

I still haven't found a way around that myself unfortunately. It's the comma that is the issue unfortunately.

So at this point you probably just have to loop through the records and build the table row by row.

@PaiChung Thanks for checking, I'm already looping through records. Was looking how to handle this in expression.

 

 

Top Tags