-
Notifications
You must be signed in to change notification settings - Fork 906
Onchange validation client script based on category, priority and urgency #2518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
Client-Side Components/Client Scripts/Onchange Validation Client Script/Readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
50 changes: 50 additions & 0 deletions
50
...nts/Client Scripts/Onchange Validation Client Script/onchange_validation_client_script.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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..?