Skip to main content
Nov 30, 2020 9:17 AM UTC
Question

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

Nov 30, 2020 5:17 PM UTC

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

abhiramkAuthor
Dec 1, 2020 10:42 AM UTC

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

Dec 1, 2020 3:13 PM UTC

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