Client Scripts
Confirmation Dialog Before Save
Show a confirmation dialog before saving the form when certain conditions are met (e.g., warn user about critical changes).
function onSubmit() {
// Configuration: Define when to show confirmation
var showConfirmation = false;
var confirmMessage = '';
// Example 1: Warn when closing without resolution
var state = g_form.getValue('state');
var closeCode = g_form.getValue('close_code');
var closeNotes = g_form.getValue('close_notes');
if (state === '6' || state === '7') { // Resolved or Closed
if (!closeCode || closeCode === '') {
showConfirmation = true;
confirmMessage = 'You are closing this incident without a close code. Are you sure you want to continue?';
}
}
// Example 2: Warn when changing priority on high-impact incident
// Uncomment to enable
/*
var priority = g_form.getValue('priority');
var impact = g_form.getValue('impact');
var urgency = g_form.getValue('urgency');
if (impact === '1' && priority !== '1') {
showConfirmation = true;
confirmMessage = 'This is a high-impact incident but priority is not Critical. Continue anyway?';
}
*/
// Example 3: Warn when reassigning multiple times
// Uncomment to enable
/*
var reassignmentCount = g_form.getValue('reassignment_count');
if (parseInt(reassignmentCount) > 3) {
showConfirmation = true;
confirmMessage = 'This incident has been reassigned ' + reassignmentCount + ' times. Are you sure you want to save?';
}
*/
// Example 4: Warn about empty work notes
// Uncomment to enable
/*
var workNotes = g_form.getValue('work_notes');
var stateChanged = g_form.hasChanged('state');
if (stateChanged && (!workNotes || workNotes === '')) {
showConfirmation = true;
confirmMessage = 'You are changing the state without adding work notes. Do you want to continue?';
}
*/
// Show confirmation dialog if conditions are met
if (showConfirmation) {
var confirmed = confirm(confirmMessage);
if (!confirmed) {
// User clicked Cancel - prevent form submission
return false;
}
}
// Allow form submission
return true;
}How to use it
1. Create an onSubmit Client Script on your table 2. Customize the conditions for showing the confirmation 3. Update the confirmation messages for your use case 4. Uncomment additional examples as needed 5. Test by attempting to save the form under various conditions
Adapt the table names, fields, and conditions to your instance. Test the behavior in a development environment before using it in production.