Client-side JavaScript

The client-side JavaScript API includes functions, objects with interfaces, properties, and events. You can use the JavaScript API anywhere you can create a client-side script, for example, in a script component on a page or in a custom header. See Adding business logic for information about where you can use client-side scripts. See Programmatic client-side customization for examples of script components.

Note:

The methods in this section apply to the new UI, not the classic UI. Most Platform tenants are using the new UI. However, tenants on older Private Cloud installations might still be using the classic UI.

These methods are not supported in portals.

Executing a script before the UI starts

You can add custom scripts to the sidebar and to the header and footer for your application. Typically, these scripts execute after the UI is rendered so that they can access, modify, or add elements to the page. However, there might be situations where you need to execute code before the UI is rendered. For example, you might want to modify some rb.newui.options. Platform allows you to specify one script in the custom sidebar to be executed before the UI starts. The script tag for that script must include id="executeBeforeUIStarts". The script will be executed only once and it will be executed before the UI starts rendering. A custom sidebar can also contain other scripts, which will be executed after the UI has rendered.

The following example is a script in a custom sidebar that will execute before the UI starts:

<script id="executeBeforeUIStarts">
    try {
        if ( window.rb !== undefined && window.rb.newui !== undefined ) {
            console.log("*** Executing Custom Sidebar for New UI");
            rb.newui.options.filters.showAdvancedFilterTypes = false;
        }
    }
    catch (e) {alert ('Error in custom sidebar code' + e);
}
</script>

Debugging scripts

You can use the debugger statement to set a breakpoint in a script. This causes execution to pause. The following example sets a breakpoint in a script:

<script id="executeBeforeUIStarts">
    try {
        if ( window.rb !== undefined && window.rb.newui !== undefined ) {
            console.log("*** Executing Custom Sidebar for New UI");
            debugger; // set breakpoint
            rb.newui.options.filters.showAdvancedFilterTypes = false;
        }
    }
    catch (e) {alert ('Error in custom sidebar code' + e);
}
</script>