Category:
Updated on: August 30, 2025  |  0

Client Script Patterns 2 -OnSubmit & OnCellEdit

🔧 Client Script Patterns:

Examples & Scenarios

 

3) onSubmit: block or shape submission

 
function onSubmit() { // Example: require at least one Affected CI var count = g_form.getRelatedListCount('task_ci'); // works on platform UI if (!count || count === 0) { g_form.addErrorMessage('Add at least one Affected CI before submitting.'); return false; } return true; }

3.2 Confirm destructive action

 
function onSubmit() { if (g_form.getValue('priority') == '1') { return confirm('Submit as CRITICAL? This will page the on-call team.'); } return true; }

3.3 Cross-field logical validation

 
function onSubmit() { var state = g_form.getValue('state'); var resolution = g_form.getValue('close_notes') || g_form.getValue('resolution_notes'); if (state == '7' && !resolution) { // e.g., "Closed" g_form.addErrorMessage('Resolution notes are required to close this record.'); return false; } return true; }

4) onCellEdit (list editing): fast grid rules

Signature varies by release. A common pattern:
function onCellEdit(sysIDs, table, oldValues, newValue, callback) { ... }

4.1 Prevent setting past due date in list

 
function onCellEdit(sysIDs, table, oldValues, newValue) { if (!newValue) return true; var picked = new GlideDateTime(newValue); if (picked.before(new GlideDateTime())) { alert('Due date cannot be in the past.'); return false; } return true; }

4.2 When priority changes in list, auto-set urgency (silent)

 
function onCellEdit(sysIDs, table, oldValues, newValue) { if (table !== 'incident') return true; var column = g_list.getEditedColumnName(); // available in list edit context if (column == 'priority' && newValue == '1') { g_list.setCellValue('urgency', '1'); // adjusts edited row’s cell } return true; }

Comments

No comments yet.


Log in to post a comment