\OCP\Util::addScript('myapp', 'myscript') parametrs?

When running
\OCP\Util::addScript('myapp', 'myscript')
Is it possible to add paraments to the script that is run?
I have now

// myapp/js/my_script.js
(function() {
    console.log('Hello from Nextcloud JavaScript!');
    alert("hello world");
})();

If you want to pass information from PHP to your JS, use the initial state functionality:

https://docs.nextcloud.com/server/latest/developer_manual/basics/front-end/js.html#loading-initial-state

I added as in the manual

const state = OCP.InitialState.loadState('myapp', 'MyState');

but got an error Could not find initial state MyState of myapp. What is MyState supposed to be?

You have to provide the initial state yourself, as described in the documentation i linked.

So add the OCP\AppFramework\Services\IInitialState service to your controllers __construct method and then use the functions of that service to provide the state.

class MyCrontroller {

    public function __construct(
        string $appName
        \OCP\IRequest $request,
        protected \OCP\AppFramework\Services\IInitialState $initialState,
    ) {
        parent::__construct($appName, $request);
    }

    public function index(): TemplateResponse {
// other controller stuff
        $this->initialState->provideInitialState('MyState', 'some value');
// other controller stuff
    }
}

You’re using “MyState”, but you can use anything else. Also “my-app” must be the appname of your app.