Modbus binding - how to do JavaScript transformation in OH 4?

I have upgraded from OH 3.4.4 to OH 4.0.1 and immediately I found all my JavaScript transformation stops working. I found some discussion in this post and tried to modify my script/things configuration however still can’t make it work hence need some advice here.
Below is how it looks like in Things:

	Bridge poller VentilationWrite [ start=4746, length=2, refresh=10000, type="holding" ] {
		Thing data hold4747 [ readStart="4747", readValueType="int16",writeStart="4747", writeValueType="int16", writeType="holding", readTransform="SCRIPT:graaljs:speedToPct.script", writeTransform="SCRIPT:graaljs:pctToSpeed.script"  ]


The speedToPct.script:

(function(i) {

return (i - 100) * 25;


The pctToSpeed.script:

(function(i) {

return 100 + Math.round(i / 25);


However the transformation doesn’t work and I see lots of errors like this:

2023-08-12 07:57:34.825 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'SCRIPT' is unavailable

I have JavaScript scripting and JavaScript Scripting (Nashorn) installed.
What is the right approach to migrate JavaScript transformation to OH 4? If JavaScript is not going to be supported is there any other/better way to implement the transformation?
Thank you in advance!

Read the thread you mentioned till the end.
It looks like you just used what was marked as the solution.
There was a change in an other Milestone release afterwards so the syntax changed.

See also this post and surrounding posts.

1 Like

SCRIPT transformation syntax has changed in OH4. Instead of writing SCRIPT:graaljs:yourtransformation.script, you would write: JS:yourtransformation.js and note the file name should be changed from .script to .js

See Transformations | openHAB

1 Like

Thank you for the help, it solves the problem!

Ok, looks like after I clear the cache (tmp and cache folders) it stops working, now the error shows

couldn't transform response because transformationService of type 'JS' is unavailable

I have reinstalled JavaScript scripting add-on without luck

Make sure to install the new graalvm JS, not nashornjs

Is this one correct? I already tried to reinstall this one without luck, configuration of the add-on also added.

Yes that is the correct one. Not sure what else to suggest. Have you tried restarting openhab?

Hi @JimT : thank you for your reply! I have restarted multiple times and eventually it started to work. The start up of OH 4 becomes very indeterministic, I have seem strange issues like things configurations not loaded randomly during startup, clearing cache doesn’t help. Thank you very much for helping with the transformer issue!