Skip to main content
8-Gravel
October 26, 2023
Solved

Template literals cant use in thingworx

  • October 26, 2023
  • 2 replies
  • 2132 views

Hello,

  I have a long string part of which need to be replaced to make read easier. But template literal error arises. How can I modify my code? Or how to update js engine?

  • my code

 

 

var age = 10;
let result = `I am ${age} years old`;​

 

 

  • error
  • 20231026-154329.jpgversion: ThingWorx 9.3.1 

BR

 

 

Best answer by rogerjn

Hello,

 

There is a workaround, but not likely to be supported by PTC.

You can download the Rhino JAR file from Mozilla for version 1.7.14 and replace in the webapps/META-INF/lib folder. Restart ThingWorx and you can use string template literals.

2 replies

16-Pearl
October 26, 2023

Hello @LeoChen 

 

Can you try the following code ?

 

var age = 10;
let result = 'I am'+ age+' years old';

 

Let me know if this is not what you are expecting.

 

thanks

Om

LeoChen8-GravelAuthor
8-Gravel
October 30, 2023

This is how code works for now, but its actually a long string with params. So what my code looks like

// "......" indicates omission
let A1 = "y1";
let A2 = "y2";
...... 
let A20 = "y20"

let result = "xxxx" + A1 + "xxx" + A2 + ...... + "xxx" + A20;

That is too long and difficult to read.

17-Peridot
November 3, 2023

@LeoChen ,

 

You are trying to use the JavaScript feature of 'Template Strings', The engine which provide Java Script is "Rhino JavaScript Engine".
If you look at the online ThingWorx Documentation "Rino JavaScript Engine" is version 1.7.11 

A Google Search located a StackOverFlow post which confirms that the "Template Strings" is not supported.
If you look at the support matrix of features the feature you are looking for will not be available until Rhino version 1.7.14 or greater since the work is incomplete.
HTH
Pehowe

rogerjn14-AlexandriteAnswer
14-Alexandrite
November 7, 2023

Hello,

 

There is a workaround, but not likely to be supported by PTC.

You can download the Rhino JAR file from Mozilla for version 1.7.14 and replace in the webapps/META-INF/lib folder. Restart ThingWorx and you can use string template literals.

LeoChen8-GravelAuthor
8-Gravel
November 8, 2023

Thank you for your solution.