|
1 | | -Edit Last Entered Work Notes/Additional comments |
| 1 | +# ✏️ Edit Last Work Notes or Comments via Modal (Client UI Action) |
2 | 2 |
|
3 | | -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. |
| 3 | +## 📁 Location |
| 4 | +**Category:** `Client-Side Components` |
| 5 | +**Subcategory:** `UI Actions` |
| 6 | +**Snippet Folder:** `Edit Last Comments Modal` |
4 | 7 |
|
5 | | -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 |
6 | | -UI action which calls the UI pages which will automatically populates the last entered work notes/comments and user can adjust and submit it. |
| 8 | +--- |
| 9 | + |
| 10 | +## 📌 Description |
| 11 | + |
| 12 | +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. |
| 13 | + |
| 14 | +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. |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## 🚀 Features |
| 19 | + |
| 20 | +- 🪟 Opens a modal dialog using `GlideModal` |
| 21 | +- ✏️ Allows quick editing of the latest Work Notes or Additional Comments |
| 22 | +- 🔄 Passes the current Incident `sys_id` to the UI macro using `setPreference()` |
| 23 | +- 🎨 Sets modal width and title for a better user experience |
| 24 | +- 🧩 Seamlessly integrates into the form via a client-side UI Action |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## 🧪 Example Use Case |
| 29 | + |
| 30 | +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: |
| 31 | + |
| 32 | +1. Click the **“Edit Last Comment”** button on the form. |
| 33 | +2. A modal opens, pre-populated with the last comment. |
| 34 | +3. They update and save — without navigating away from the current form. |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## 📄 Script: `UIAction.js` |
| 39 | + |
| 40 | +```javascript |
| 41 | +/** |
| 42 | + * Opens a modal to edit the last Work Notes or Additional Comments. |
| 43 | + * |
| 44 | + * Usage: |
| 45 | + * - UI Action: Client = true |
| 46 | + * - OnClick: openEditLastCommentModal() |
| 47 | + * - Form Button: true |
| 48 | + */ |
| 49 | +function openEditLastCommentModal() { |
| 50 | + var dialog = new GlideModal("edit_worknotes_comments_inc"); |
| 51 | + dialog.setTitle("Edit Last WorkNotes/Additional Comments"); |
| 52 | + dialog.setPreference("incid", g_form.getUniqueValue()); |
| 53 | + dialog.setWidth(550); |
| 54 | + dialog.render(); |
| 55 | +} |
| 56 | + |
| 57 | +🛠️ How to Use |
| 58 | + |
| 59 | +1) Create a UI Action on the incident table with the following settings: |
| 60 | + Client: true |
| 61 | + Form Button: true |
| 62 | + OnClick: openEditLastCommentModal() |
| 63 | + |
| 64 | +2) Add the above function to a client script file or ensure it is loaded with the UI Action. |
| 65 | +3) Ensure a corresponding UI Macro (edit_worknotes_comments_inc) exists that supports editing based on the provided sys_id. |
| 66 | + |
| 67 | +📂 File Structure |
| 68 | + |
| 69 | +Client-Side Components/ |
| 70 | +└── UI Actions/ |
| 71 | + └── Edit Last Comments Modal/ |
| 72 | + ├── README.md |
| 73 | + └── UIAction.js |
| 74 | + |
| 75 | +📘 Dependencies |
| 76 | + |
| 77 | +1) A working UI Macro named edit_worknotes_comments_inc that accepts the incid preference. |
| 78 | +2) GlideModal API must be available on the form (standard in UI16+). |
| 79 | +3) Script must run on a form context (g_form). |
| 80 | + |
| 81 | +✅ Contribution Checklist Compliance |
| 82 | + |
| 83 | +✔️ Code placed under correct category (Client-Side Components/UI Actions) |
| 84 | +✔️ README.md provided with description and usage |
| 85 | +✔️ Code snippet is self-contained and relevant to ServiceNow developers |
| 86 | +✔️ No XML or server-specific exports included |
| 87 | +✔️ Uses modern, maintainable JavaScript practices |
| 88 | + |
| 89 | +👤 Author |
| 90 | + |
| 91 | +Contributor: @Shweyy123 |
| 92 | +Script Name: UIAction.js — Open Modal for Editing Last Comments |
| 93 | +PR Title: Added modal function to edit last Work Notes or Comments |
| 94 | + |
| 95 | +📘 License |
| 96 | + |
| 97 | +This script is shared for educational and developmental use. Test thoroughly in non-production environments before implementation. |
| 98 | + |
| 99 | +🧩 Optional Enhancements |
| 100 | + |
| 101 | +1) Extend to support both Work Notes and Additional Comments with tab-based UI |
| 102 | +2) Add history tracking or audit log of modal-based edits |
| 103 | +3) Support additional tables like change_request or problem |
0 commit comments