|
1 | | -// Business Rule: Set Resolution SLA on Related Tasks |
2 | | -// Table: task_sla |
3 | | -// When: After Insert |
| 1 | +//Client Script to validate an Interaction record is resolved with out any related record created. |
| 2 | +function onSubmit() { |
| 3 | + var relatedTask = g_form.getValue('u_boolean_no_related_task'); |
| 4 | + var state = g_form.getValue('state'); |
| 5 | + var type = g_form.getValue('type'); |
| 6 | + var workNotes = g_form.getValue('work_notes'); // Get the value of work notes |
4 | 7 |
|
5 | | -// PURPOSE: |
6 | | -// When a new Task SLA is created for Resolution SLA, update the related records. |
| 8 | + // Clear previous field messages |
| 9 | + g_form.clearMessages(); |
7 | 10 |
|
8 | | -// CONDITIONS: |
9 | | -// SLA Definition target = "Resolution" |
10 | | -// Run only if task is Incident or SC Task |
11 | | -// (current.task.sys_class_name == 'incident' || current.task.sys_class_name == 'sc_task') |
12 | | - |
13 | | -// STEP 1: |
14 | | -// Get the related Incident record from current.task reference |
15 | | -var inc = new GlideRecord('incident'); // Query Incident table |
16 | | -inc.get(current.task); // Fetch the matching incident record |
17 | | - |
18 | | -// Update Incident’s custom field to store the Resolution SLA reference |
19 | | -inc.u_resolution_sla = current.sys_id; // Set current task_sla sys_id |
20 | | -inc.update(); // Save changes to Incident |
21 | | - |
22 | | -// STEP 2: |
23 | | -// Get the related Task record from current.task reference |
24 | | -var tsk = new GlideRecord('task'); // Query Task table |
25 | | -tsk.get(current.task); // Fetch the task (incident/sc_task/etc.) |
26 | | - |
27 | | -// Update Task’s custom field to store the Resolution SLA reference |
28 | | -tsk.u_task_resolution_sla = current.sys_id; // Set current task_sla sys_id |
29 | | -tsk.update(); // Save changes to Task |
| 11 | + // Check if state is changing to 'Closed Complete' |
| 12 | + if (state == 'closed_complete') { |
| 13 | + // Check additional conditions |
| 14 | + if (type == 'walkup' && relatedTask == 'true') { |
| 15 | + return true; // Allow form submission |
| 16 | + } else if (!workNotes) { // Check if work notes is empty |
| 17 | + g_form.showFieldMsg('work_notes', 'Provide Worknotes for FCR Interaction', 'error'); |
| 18 | + alert('Provide Worknotes for FCR Interaction'); |
| 19 | + return false; // Prevent form submission |
| 20 | + } |
| 21 | + } |
| 22 | + return true; // Allow form submission for other states |
| 23 | +} |
0 commit comments