External JavaScript Extensions
From codebeamer 22.04 (Felicity), external JavaScript and CSS files can be used to extend codebeamer functionality and customize the UI.
The following pages can be extended and customized with extensions:
- Tracker Views
- Tracker Item Views
- Reference selector
- Reports
UI model used by scripts can change in any release including service packs without notice. Maintaining and confirming compatibility of the scripts with a particular version is the responsibility of the partner sharing the scripts with customers.
Using external scripts
The following should apply to custom script files before they can be loaded and used:
- Script files must be located in <codebeamer Installation dir>/repository/config/customization/js before starting codebeamer. If codebeamer is running, changes made to the folder or the script files are not processed until codebeamer is restarted.
- Custom scripts must be wrapped in jQuery's load function.
- externalScripts must be enabled in Application Configuration.
Wrapping external scripts
In order for the DOM to be ready, external scripts have to be wrapped in jQuery's load function, in the following way:
$(window).on('load', function() {
...
<external script>
...
});
Application Configuration
Loading external scripts to various codebeamer pages can be enabled or disabled in System Admin ► Application Configuration menu, by adding the following section:
...
"externalScripts" : {
"enabled" : true
}
...
The default value is false.
For more information about the Application Configuration, see: Application configuration.
Example
This example provides a step-by-step description of using scripts for customizing and extending codebeamer functionality and UI, given that appropriate settings were applied in Application Configuration before. In this example, the page title of the Reports ► New Report page changes color to red and back to white when clicked.
- Stop codebeamer.
- Download the following files:
- Copy the files to <codebeamer Installation dir>/repository/config/customization/js, before starting codebeamer.
- Start codebeamer.
- Go to Reports ► New Report page.
- Click the page title: 'New Report', it should change to red.
- Click the title again, it should change back to wihte.
- Console log should display the following message: external script - title clicked.
- A message with the same text is also recorded in codebeamer log.
Content of files
script.js:
$(window).on('load', function() {
const msg = "external script - title clicked";
$( ".page-title" ).click(
function() {
$(this).toggleClass( "title-red" );
console.log(msg);
codebeamer.MessageLogger.error(msg);
}
);
});
style.css:
.title-red {
color: red !important;
}