Use cases and sample scripts designed to work with Setup (Custom Scripts) Customization.
Here are some example use cases that can be satisfied by the use of Custom Scripts:
When making fields mandatory within a pop up, we use the Ext JS ‘set‘ method to reload the element with the correct validation.
‘Set‘ is used because changing the value of an element’s mandatory property to True will NOT add validation to the form until the element is reloaded.
The following script will set all Additional Information fields to be mandatory:
model.additionalInfoPanel = getComponent('changeRequestCustomFieldsId');
var additonalFields = model.additionalInfoPanel.store.data.items;
additonalFields.forEach(function(field){
field.set('Mandatory', true);
});
Once run, all the fields on the Additional Information panel will have asterisks, showing that they are mandatory.
To display a message box or pop up alert with Release & Verify's default styles, use the Ext JS ‘Ext.MessageBox.show‘ method.
The fn property will execute a function after the user has closed the message box.
function showMessage() {
Ext.MessageBox.show({
title: 'Warning',
message: typeName + " duration is limited to two weeks.",
buttons: Ext.Msg.OK,
icon: Ext.Msg.WARNING,
fn: function () {
model.endField.expand();
}
});
};
Adding listeners to buttons or fields is necessary when adding custom validation or when changing behavior based on inputs from the user. The sample below adds a change listener to the TECR Type menu. When a user makes a selection initValidators (a function defined in the CustomScripts scope) is run.
function initValidators() {
// custom script Function
}
model.crType = getComponent("CRType_ID");
model.crType.on('change', initValidators, this);
To remove the listener from the element.
model.crType.removeListener('change', initValidators, this);
To disable sections or elements one they have been referenced use the Ext JS ‘setDisabled‘ method.
model.endField = getComponent('bookingInformationWindowEndDateField');
model.endField.setDisabled(false);
You can also use the Ext JS ‘mask‘ method, which will also allow you to show a message to the user. The default style of this mask is quite dark and has a loader, which we can override using JQuery.
model.SubPanel.body.mask('TEBR must be saved before making any
environment selections', '');
$('.x-mask').css('backgroundColor', 'rgba(255,255,255,0.7);');
$('.x-mask-msg-text').css({
'backgroundImage': 'none',
'padding': '0'
});
TIP
External API calls can now be made from custom scripts by redirecting the request, wrapped in an Ajax call, through a proxy.
The following script gets data from Release & Verify and console logs the data.
console.log('Open Trigger');
var data = JSON.stringify({"ReleaseIds":[],"NoRelease":false,"PageNum":0,"RecordsPerPage":25,"SearchFilters":[],"DataGridName":"Defect"});
$.ajax({
type: "POST",
url: "/proxy/api/Defects/Search",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: (data) => {
console.log(data);
},
xhrFields: {
withCredentials: true
}
});