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 an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to provide comma in derive fields expression

abhiramk
13-Aquamarine

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"

abhiramk
13-Aquamarine
(To:PaiChung)

@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.

abhiramk
13-Aquamarine
(To:PaiChung)

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.

abhiramk
13-Aquamarine
(To:PaiChung)

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

 

 

Announcements


Top Tags