CustomizeJS and LoadAndRun are JavaScript files which can be loaded in the AMT Web Client in order to customize the application.
These script files can be configured in the appsettings.json file of the Blazor web client Server Web Application.
As this functionality is not part of the main AMT product suite, while unlikely, it is possible that specific functions are changed with newer AMT versions.
Due to the custom nature of this script customers are advised to test their CustomizeJS and LoadAndRun scripts thoroughly themselves when upgrading the AMT environment to a newer version.
This script is loaded in the application once when the web client has finished loading. It can be used to customize the web client, e.g. to add custom buttons, change the look and feel, or to add custom functionality.
The LoadAndRun JavaScript script is a customer specific customization which can modify the values to and from an AMT web client form by hooking into the form at certain loading stages on runtime.
These stages are:
The hooks must be created with the following syntax:
async function LoadObjects() {
// your custom implementation
}
async function RunObjects() {
// your custom implementation
return true; // return false to block the transmit
}
async function RefreshObjects() {
// your custom implementation
}
The WebClient API provides a collection of JavaScript methods and classes that allow you to interact with and customize the WebClient interface. These methods are designed to help developers set and retrieve values, modify component states, and manage UI updates effectively. However, the API is intentionally limited to operations that directly affect the WebClient and its components.
Key points:
AmtThis namespace contains all classes and enums necessary to interact with the web client.
AmtControlThis abstract base class is used to interact with the controls in the web client. It provides methods to get and set values. All specific AmtControl implementations (e.g. AmtButtonGroup, AmtLabel, etc.) inherit this base class.
getValue(): Promise<string>This method gets the formatted AMT value of the control. It returns a promise that resolves with the current value:
Formatted value means the value that AMT is using on the backend. For example, when a control has the value type boolean getValue will return either 'T' or 'F'.
Since all control types are inheriting from AmtControl, this method is available on all control classes. However, it is only functional for the following types: AmtButtonGroup, AmtCalendar, AmtCheckbox AmtComboBox, AmtEdit, AmtLabel, AmtListBox, AmtMaskEditBox, AmtMemo and AmtRadioButton. If the method is used unsupported controls, an error will be thrown.
let myLabel = new Amt.AmtLabel('DISPLAY_0');
let myLabelValue = await myLabel.getValue();
setValue(value: string): Promise<void>This method sets the value of the control. It returns a promise that resolves when the value is set.
The provided value must comply with the formatted AMT value. The same format as used in getValue is expected. For example, when setting a boolean value, you should use 'T' or 'F'. Using wrong formatted values may result in unexpected behavior or errors.
Since all control types are inheriting from AmtControl, this method is available on all control classes. However, it is only functional for the following types: AmtButtonGroup, AmtCalendar, AmtCheckbox AmtComboBox, AmtEdit, AmtLabel, AmtListBox, AmtMaskEditBox, AmtMemo and AmtRadioButton. If the method is used unsupported controls, an error will be thrown.
The value will only be set if the control isn’t readonly or disabled. If the control is readonly or disabled, an error will be thrown.
let myLabel = new Amt.AmtLabel('DISPLAY_0');
await myLabel.setValue('New Value');
getElement(): HTMLElement | nullThis method returns the HTML element associated with the control. It can be used to manipulate the DOM directly if needed. If the element could not be found, it returns null:
let myLabel = new Amt.AmtLabel('DISPLAY_0');
let myLabelElement = myLabel.getElement();
AmtListControl extends AmtControlThis abstract base class is inherited by the list controls in the web client (AmtComboBox and AmtListBox). It provides the ability to set list items.
setListItems(items: [{ Text: string, Value: any }]): voidThis method sets the list items for the control. It takes an array of objects with Text and Value properties:
let myComboBox = new Amt.AmtComboBox('COMBOBOX_0');
myComboBox.setListItems([
{ Text: 'Item 1', Value: '1' },
{ Text: 'Item 2', Value: '2' }
]);
AmtButtonGroup extends AmtControlConstructor: new Amt.AmtButtonGroup(amtId: string, subsessionId: number = 1)
AmtCalendar extends AmtControlConstructor: new Amt.AmtCalendar(amtId: string, subsessionId: number = 1)
AmtChart extends AmtControlConstructor: new Amt.AmtChart(amtId: string, subsessionId: number = 1)
AmtCheckBox extends AmtControlConstructor: new Amt.AmtCheckBox(amtId: string, subsessionId: number = 1)
AmtComboBox extends AmtListControlConstructor: new Amt.AmtComboBox(amtId: string, subsessionId: number = 1)
AmtDatagrid extends AmtControlConstructor: new Amt.AmtDatagrid(amtId: string, subsessionId: number = 1)
AmtDynamicForm extends AmtControlConstructor: new Amt.AmtDynamicForm(amtId: string, subsessionId: number = 1)
AmtEditBox extends AmtControlConstructor: new Amt.AmtEditBox(amtId: string, subsessionId: number = 1)
AmtFileUploader extends AmtControlConstructor: new Amt.AmtFileUploader(amtId: string, subsessionId: number = 1)
AmtImage extends AmtControlConstructor: new Amt.AmtImage(amtId: string, subsessionId: number = 1)
AmtLabel extends AmtControlConstructor: new Amt.AmtLabel(amtId: string, subsessionId: number = 1)
AmtListBox extends AmtListControlConstructor: new Amt.AmtListBox(amtId: string, subsessionId: number = 1)
AmtListview extends AmtControlConstructor: new Amt.AmtListview(amtId: string, subsessionId: number = 1)
AmtMaskEditBox extends AmtControlConstructor: new Amt.AmtMaskEditBox(amtId: string, subsessionId: number = 1)
AmtMemo extends AmtControlConstructor: new Amt.AmtMemo(amtId: string, subsessionId: number = 1)
AmtMenu extends AmtControlConstructor: new Amt.AmtMenu(amtId: string, subsessionId: number = 1)
AmtPanel extends AmtControlConstructor: new Amt.AmtPanel(amtId: string, subsessionId: number = 1)
AmtRadioButtonGroup extends AmtControlConstructor: new Amt.AmtRadioButtonGroup(amtId: string, subsessionId: number = 1)
AmtScrollBox extends AmtControlConstructor: new Amt.AmtScrollBox(amtId: string, subsessionId: number = 1)
AmtShape extends AmtControlConstructor: new Amt.AmtShape(amtId: string, subsessionId: number = 1)
AmtTabSheet extends AmtControlConstructor: new Amt.AmtTabSheet(amtId: string, subsessionId: number = 1)
AmtTimer extends AmtControlConstructor: new Amt.AmtTimer(amtId: string, subsessionId: number = 1)
AmtFormThis class contains properties of the current form that is shown within the web client.
Property: activeControlName: String
Property: eventSourceName: String
Property: formName: String
Property: language: String
Property: messages: Array<String>
Property: objectFields: String
Property: userPreference: AmtUserPreference
An instance can be requested by doing the following call:
let form = await Amt.AmtFormInstance();
Documentdocument.getElementByAmtId(amtId: string, subsessionId?: number): HTMLElement | nullThis method will retrieve the right HTMLElement based on given amtId. The subsessionId is optional (defaults to 1) and needs to be used to select element within popups.
let buttongroupElement = document.getElementByAmtId('BUTTONGROUP_0');
document.getAmtControlByAmtId(amtId: string, subsessionId?: number): HTMLElement | nullThis method will retrieve the right AmtControl instance based on given amtId. The subsessionId is optional (defaults to 1) and needs to be used to select controls within popups. The type AmtControl that needs to be constructed is based on the controltype attribute within the HTML element. Therefore, the control must be rendered in the DOM before this method can be used. This is not the case when directly constructing using the constructor of the control.
let myCombobox = document.getAmtControlByAmtId('BUTTONGROUP_0');
myCombobox.setListItems([
{ Text: 'Item 1', Value: '1' },
{ Text: 'Item 2', Value: '2' }
]);
This can be realized using the LoadAndRun functionality by hooking into the LoadObject function of the LoadAndRun script:
LoadAndRun.js
async function LoadObjects() {
let currentForm = await Amt.AmtFormInstance();
if (currentForm.formName === "MY_FORM") { // only attaches handler for a specific form
let myButton = document.getElementByAmtId('BUTTONGROUP_0');
// Add an event listener to handle the click
myButton.addEventListener('mousedown', function(event) {
// To prevent the transmit, we need to prevent the default action and stop propagation:
event.preventDefault();
event.stopPropagation();
console.log("Button clicked, but transmit prevented.");
});
}
}
This can be realized using the LoadAndRun functionality by hooking into the RunObject function of the LoadAndRun script:
LoadAndRun.js
async function RunObjects() {
let currentForm = await Amt.AmtFormInstance();
if (currentForm.formName === "MY_FORM") { // only attaches handler for a specific form
let myCheckbox = document.getAmtControlByAmtId('CHECKBOX_0');
if (await myCheckBox.getValue() !== 'T') return false; // Only proceed if checkbox is checked
// In all other cases, we do not want to block the transmit:
return true;
}
}