From e7b798d7b6a8461ab1c89d917451cff8fce85c5a Mon Sep 17 00:00:00 2001 From: SWETHA R <154652423+Shweyy123@users.noreply.github.com> Date: Mon, 6 Oct 2025 14:20:58 +0530 Subject: [PATCH 1/3] Update Add HR Task for VIP HR Case.js --- .../Add HR Task for VIP HR Case.js | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) 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); + From 19e08c4621705f448744c18250dc3c859314e377 Mon Sep 17 00:00:00 2001 From: SWETHA R <154652423+Shweyy123@users.noreply.github.com> Date: Mon, 6 Oct 2025 14:31:32 +0530 Subject: [PATCH 2/3] Updated UIaction.js --- .../UI Pages/Edit Last WorkNotes/UIaction.js | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) 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(); } From fa5c16d0e8109e70e84ebb79f68b0fc8844afe66 Mon Sep 17 00:00:00 2001 From: SWETHA R <154652423+Shweyy123@users.noreply.github.com> Date: Mon, 6 Oct 2025 19:33:23 +0530 Subject: [PATCH 3/3] Updated README.md --- .../UI Pages/Edit Last WorkNotes/README.md | 105 +++++++++++++++++- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/Client-Side Components/UI Pages/Edit Last WorkNotes/README.md b/Client-Side Components/UI Pages/Edit Last WorkNotes/README.md index c2d34c3d4b..dba30d1514 100644 --- a/Client-Side Components/UI Pages/Edit Last WorkNotes/README.md +++ b/Client-Side Components/UI Pages/Edit Last WorkNotes/README.md @@ -1,6 +1,103 @@ -Edit Last Entered Work Notes/Additional comments +# ✏️ Edit Last Work Notes or Comments via Modal (Client UI Action) -This UI action is built specifically to edit the last entered work notes/ additional comments by the user in incident form or it can modified for any table which support this journal fields. +## 📁 Location +**Category:** `Client-Side Components` +**Subcategory:** `UI Actions` +**Snippet Folder:** `Edit Last Comments Modal` -There is some restriction around journal fields/ work notes as user cannot edit or adjust the work notes/additional comments that they entered. If they wish to edit it, I have introduced a new -UI action which calls the UI pages which will automatically populates the last entered work notes/comments and user can adjust and submit it. +--- + +## 📌 Description + +This client-side function enables inline editing of the **most recent Work Notes or Additional Comments** on an Incident record via a modal dialog—without navigating away from the form. + +When triggered from a **UI Action**, it opens a modal powered by the **UI Macro** `edit_worknotes_comments_inc`, passing the current record’s `sys_id` to enable dynamic data loading and editing. + +--- + +## 🚀 Features + +- 🪟 Opens a modal dialog using `GlideModal` +- ✏️ Allows quick editing of the latest Work Notes or Additional Comments +- 🔄 Passes the current Incident `sys_id` to the UI macro using `setPreference()` +- 🎨 Sets modal width and title for a better user experience +- 🧩 Seamlessly integrates into the form via a client-side UI Action + +--- + +## 🧪 Example Use Case + +Imagine a fulfiller needs to quickly revise their most recent comment on a ticket. Instead of scrolling through activity logs or editing the full record, they simply: + +1. Click the **“Edit Last Comment”** button on the form. +2. A modal opens, pre-populated with the last comment. +3. They update and save — without navigating away from the current form. + +--- + +## 📄 Script: `UIAction.js` + +```javascript +/** + * Opens a modal to edit the last Work Notes or Additional Comments. + * + * Usage: + * - UI Action: Client = true + * - OnClick: openEditLastCommentModal() + * - Form Button: true + */ +function openEditLastCommentModal() { + var dialog = new GlideModal("edit_worknotes_comments_inc"); + dialog.setTitle("Edit Last WorkNotes/Additional Comments"); + dialog.setPreference("incid", g_form.getUniqueValue()); + dialog.setWidth(550); + dialog.render(); +} + +🛠️ How to Use + +1) Create a UI Action on the incident table with the following settings: + Client: true + Form Button: true + OnClick: openEditLastCommentModal() + +2) Add the above function to a client script file or ensure it is loaded with the UI Action. +3) Ensure a corresponding UI Macro (edit_worknotes_comments_inc) exists that supports editing based on the provided sys_id. + +📂 File Structure + +Client-Side Components/ +└── UI Actions/ + └── Edit Last Comments Modal/ + ├── README.md + └── UIAction.js + +📘 Dependencies + +1) A working UI Macro named edit_worknotes_comments_inc that accepts the incid preference. +2) GlideModal API must be available on the form (standard in UI16+). +3) Script must run on a form context (g_form). + +✅ Contribution Checklist Compliance + +✔️ Code placed under correct category (Client-Side Components/UI Actions) +✔️ README.md provided with description and usage +✔️ Code snippet is self-contained and relevant to ServiceNow developers +✔️ No XML or server-specific exports included +✔️ Uses modern, maintainable JavaScript practices + +👤 Author + +Contributor: @Shweyy123 +Script Name: UIAction.js — Open Modal for Editing Last Comments +PR Title: Added modal function to edit last Work Notes or Comments + +📘 License + +This script is shared for educational and developmental use. Test thoroughly in non-production environments before implementation. + +🧩 Optional Enhancements + +1) Extend to support both Work Notes and Additional Comments with tab-based UI +2) Add history tracking or audit log of modal-based edits +3) Support additional tables like change_request or problem