Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
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?
var age = 10;
let result = `I am ${age} years old`;
BR
Solved! Go to Solution.
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.
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
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.
@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
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.
Thank you for your solution.