diff --git a/Client-Side Components/UI Pages/Edit Last WorkNotes/UIaction.js b/Client-Side Components/UI Pages/Edit Last WorkNotes/UIaction.js index 26e5381269..26916d5d3e 100644 --- a/Client-Side Components/UI Pages/Edit Last WorkNotes/UIaction.js +++ b/Client-Side Components/UI Pages/Edit Last WorkNotes/UIaction.js @@ -1,10 +1,28 @@ -//Enable client set to true -//Enter Onclick value as function name openEditLastCommentModal() -//Enter form button as true +/** + * Opens a modal to edit the last Work Notes or Additional Comments. + * + * @description + * This function is triggered by a form button (set to true), + * with client-side execution enabled. It opens a GlideModal + * using the UI macro "edit_worknotes_comments_inc" and sets + * the current incident sys_id as a preference for use within the modal. + * + * Usage: + * - Set Client = true + * - Set OnClick = openEditLastCommentModal() + * - Set Form Button = true + */ function openEditLastCommentModal() { + // Create and configure the GlideModal var dialog = new GlideModal("edit_worknotes_comments_inc"); - dialog.setTitle('Edit Last WorkNotes/Additional Comments'); - dialog.setPreference('incid', g_form.getUniqueValue()); + dialog.setTitle("Edit Last WorkNotes/Additional Comments"); + + // Pass the current record's sys_id to the modal + dialog.setPreference("incid", g_form.getUniqueValue()); + + // Optional: Adjust modal width dialog.setWidth(550); + + // Render the modal dialog.render(); } diff --git a/Server-Side Components/Business Rules/Add HR task for HR case/Add HR Task for VIP HR Case.js b/Server-Side Components/Business Rules/Add HR task for HR case/Add HR Task for VIP HR Case.js index 409f2c3505..9e131bdd2a 100644 --- a/Server-Side Components/Business Rules/Add HR task for HR case/Add HR Task for VIP HR Case.js +++ b/Server-Side Components/Business Rules/Add HR task for HR case/Add HR Task for VIP HR Case.js @@ -1,15 +1,31 @@ -// Business Rule: 'After' Insert on 'sn_hr_core_case' +// Business Rule: After Insert on 'sn_hr_core_case' (function executeRule(current, previous /*null when async*/) { - if (current.priority == "1" && current.subject_person.getValue('VIP') == 'true') { - var newTask = new GlideRecord('sn_hr_core_task'); - newTask.initialize(); - newTask.short_description = 'Priority VIP HR task for - ' + current.number; - newTask.assigned_to = current.assigned_to; - newTask.parent = current.sys_id; - newTask.insert(); - - gs.addInfoMessage('A related HR task has been created for this HR case.'); + // Check if priority is high and subject person is a VIP + const isHighPriority = current.priority == '1'; + const isVIP = current.subject_person.getValue('VIP') === 'true'; + + if (isHighPriority && isVIP) { + try { + const task = new GlideRecord('sn_hr_core_task'); + task.initialize(); + + task.short_description = `Priority VIP HR task for - ${current.number}`; + task.assigned_to = current.assigned_to; + task.parent = current.sys_id; + + const taskSysId = task.insert(); + + if (taskSysId) { + gs.addInfoMessage('✅ A related HR task has been successfully created for this VIP HR case.'); + } else { + gs.addErrorMessage('⚠️ Failed to create HR task for VIP case.'); + } + + } catch (err) { + gs.error('Error while creating VIP HR Task: ' + err.message); + } } })(current, previous); +