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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Template literals cant use in thingworx

LeoChen
7-Bedrock

Template literals cant use in thingworx

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

 

 

ACCEPTED SOLUTION

Accepted Solutions
rogerjn
13-Aquamarine
(To:LeoChen)

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.

View solution in original post

5 REPLIES 5

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

LeoChen
7-Bedrock
(To:odukiya)

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.

PEHOWE
17-Peridot
(To:LeoChen)

@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

rogerjn
13-Aquamarine
(To:LeoChen)

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.

LeoChen
7-Bedrock
(To:rogerjn)

Thank you for your solution. 

Announcements


Top Tags