Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This client script dynamically controls field visibility, auto-calculates priority,
and validates user input on the Incident form based on category, impact, and urgency — all without using a Script Include.

it runs whenever the Category field value changes on the form.

1.Validate form fields before saving (example: block submission if “Impact” or “Urgency” is empty).
2.Auto-calculate “Priority” based on “Impact” and “Urgency.”
3.Hide or show fields depending on “Category.”
4.Dynamically filter “Assignment Group” choices based on “Department.”

Uses:
Runs when Category changes on the Incident form.
Dynamically shows/hides the Serial Number field.
Auto-calculates Priority purely on the client side (no server calls).
Displays inline error messages or alerts based on user input.
Enforces logic that prevents invalid combinations.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

// Example: Dynamic behavior when Category changes
var category = g_form.getValue('category');
var impact = g_form.getValue('impact');
var urgency = g_form.getValue('urgency');

// Hide or show certain fields dynamically
if (category === 'hardware') {
g_form.setVisible('u_serial_number', true);
g_form.setMandatory('u_serial_number', true);
} else {
g_form.setVisible('u_serial_number', false);
g_form.setMandatory('u_serial_number', false);
}

// Auto-calculate Priority based on Impact & Urgency
// (Client-only logic — no Script Include needed)
var priorityMap = {
'1_1': '1',
'1_2': '2',
'1_3': '3',
'2_1': '2',
'2_2': '3',
'2_3': '4',
'3_1': '3',
'3_2': '4',
'3_3': '5'
};

var key = impact + '_' + urgency;
var newPriority = priorityMap[key] || '5';
g_form.setValue('priority', newPriority);

// how a dynamic message when conditions are met
if (category === 'hardware' && urgency === '1') {
g_form.showFieldMsg('category', 'Critical hardware issue detected! Escalate immediately.', 'error');
} else {
g_form.hideFieldMsg('category');
}

// Prevent invalid data combination (client-side validation)
if (category === 'software' && impact === '1' && urgency === '1') {
alert('High impact & urgency for software incidents require manager approval before submission.');
g_form.setValue('state', ''); // Reset state to stop progression
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @arigalamani
Why is the state being set to empty value here..?

}
}
Loading