Template literals cant use in thingworx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
version: ThingWorx 9.3.1
BR
Solved! Go to Solution.
- Labels:
-
Analytics
-
Containers
- Tags:
- thingworx
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you for your solution.
