Pattern Transformation Call Script from UI

Hello together,

i created under OH3 scripts a script. I want to try to parse something via State Description Pattern.
Normally with JS code we must do it like [JS(scriptname.js):%s].
But how can i call this script if this script is create via UI?
I tried something like [SCRIPT(scriptname):%s] but get log errors Script

Type must be prepended to transformation UID


When you create a script in the UI you normally fill out the name. You have the possibility to add a description and of course the content of the script itself.
But there is also a field called UID ( above the name field ).
The UID is precreated by the UI. It is possible to change it manually.
Did you try to use the UID instead of the name ?

The error message is thrown by following code:

    public @Nullable String transform(String function, String source) throws TransformationException {
        Matcher configMatcher = SCRIPT_CONFIG_PATTERN.matcher(function);
        if (!configMatcher.matches()) {
            throw new TransformationException("Script Type must be prepended to transformation UID.");

where SCRIPT_CONFIG_PATTERN.matcher is defined as:

    private static final Pattern SCRIPT_CONFIG_PATTERN = Pattern
1 Like

Yes I use the right UID it’s the same as the scriptname.

You cannot do something like this. Unfortunately the word “script” is used in many places in OH but this does not mean that they are interchangeable. You cannot use a UI defined script in a transform. A UI defined script is actually just the action part of a rule (that is, a rule without a defined trigger). So these UI scripts can be used anywhere a rule could be used. For example called by pressing a button on the UI or run as as the result of the action of some other rule.

There are still some pieces of OH configuration that the UI has not been built to accommodate yet, and transforms that are file-based and get placed in the transforms folder is one of those things. If you are going use thoseyou have to make the files and place them in the folder manually.

If the js script that you are using in the transform is a pretty simple one line function, however, then you can skip the transform file altogether, and enter the js directly into the transform statement. See the inline example in the docs:


Thanks for your explanation. I don’t expect that. The other method is clear for me. But i didn’t understand well how scripts working in UI.