Assistance Required to Execute Code Globally on All Pages

Hey
I am facing an issue with my application on Backendless. Currently, a specific code executes only on one page (e.g., the 404 page). However, I would like this code to apply globally, meaning it should execute on all pages of the application as soon as it loads.

Could you please guide me on how to configure this?
Here are some additional details for context:

  • Current page affected: 404 Page
  • Objective: Execute the same code globally across all pages of the application.

Thank you in advance for your support. Please let me know if you need any additional information.

Best regards,

image

Hi @ALA

You can create a custom function and add into it the custom code block, then use the custom page on all pages you need

Regards, Vlad

Thank you for your response. I understand that I need to create a custom function and add my custom code block to it. However, I would like further clarification on the following point:

How can I ensure that this custom function is executed globally across all pages of the application, not just a specific page? I have a script that needs to run to retrieve data across the entire application, so it is crucial that the function applies globally.

I appreciate your guidance on how to achieve this.

could you please provide an example describing your use-case?
are you going to put the retrieved data into any data model?
are you going to get use the retrieved data on any page UI?

if you just need to run some JS code which works independent of pages you can use External Libraries, the section is located under the Settings tab. You can create a js file and then attach it to the UI Container (the js file can be located in the UI Container files)

Thank you for your detailed response. Let me clarify my use case:

I have a JavaScript function that fetches variables from a database via an API call when the application starts. The retrieved variables are then applied as CSS custom properties (e.g., for themes)

ok, in that case you need the External Libraries way.

  1. create a JS file with all necessary code and put it into the UI Container folder, you can find in in the Files service by the following path: /ui-builder/containers/{CONTAINER_NAME}.
  2. in the UI Builder open Settings => Libraries and add a link to the file, I do remember it should start with dot or not, so try both
  • ./your-file.js
  • /your-file.js

after that open your app in the preview and check