Change Page of an app within javascript

  • Goal: I try to switch a page with a javascript query.

  • Details: I have a one button which represents the login and logout option. If I logged in, the button changes his text to 'logout'. If nobody is logged in, the button text is 'login'. If I press the button in 'login' state I want to change the page. If I press the button in 'logout' state a logour query will run.

  • I tried to run a javascript query with no success: the script dont change to the loginPage. I could not find any help in the documentation or here. At the moment I solved the problem with two event handlers looking to the flag. But I am very disappointed about can't find a solution with one java script. ChatGPT suggested a utils.navigate() function, but this function does not exist.

// open login page
if (var_userLoggedinStatus.value == false) {
  utils.openApp({ pageName: 'loginPage' } );
}
// run logout script
else {
  jsQuery_logoutUser.trigger();
}

Can you tell me the right syntax to change a page in a javascript query? It seems very complex. I don't know how!

Greetings Georg

Hi @bauergeorg,

You need to provide the apps UUID first. It's in the url when you're editing the app. The final call will look more like this:

utils.openApp('5607783d-b8c3-21ef-e8f3-93623ccb5f82', {pageName: 'loginPage'})

The UUID is in the address bar, this part:

https://domain.retool.com/editor/5607783d-b8c3-21ef-e8f3-93623ccb5f82/Folder/App/PageName
1 Like

@MikeCB thanks for your reply! I found out, that the app uuid is available in the app context!

I implemented this solution:

  // switch to login page
  utils.openApp(retoolContext.appUuid, {pageName: 'loginPage'});

Thanks a lot! I am very disappointed with the poor documentation...

1 Like

We'll make a request to update the docs with an example. Thanks!

1 Like