Skip to main content
1-Visitor
November 30, 2020
Question

How to provide comma in derive fields expression

  • November 30, 2020
  • 1 reply
  • 2987 views

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

1 reply

22-Sapphire I
November 30, 2020

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

abhiramk1-VisitorAuthor
1-Visitor
December 1, 2020

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

22-Sapphire I
December 1, 2020

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