I've now tried to do the same when using the action "Run Real JavaScript". So far I can't get it to work, also the documentation didn't bring me further.
just search for set_string_variable on the docs page you linked, it should have an example how to do this with JS. (all BTT script interfaces can be called like this from JS)
I tried that before but always got an error. Figured it out now.
In case anyone else is struggling with it: Instead of just taking the example for set_string_variable, you need to open it with an "(" and accordingly then close it with "})();", instead of "}();".
So this:
async ()=> {
let result = await callBTT('set_string_variable', {variable_name: 'customVariable1', to: "this is a test value"});
returnToBTT(result);
}();