Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Client-Side Components/UI Pages/Edit Last WorkNotes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Edit Last Entered Work Notes/Additional comments

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.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
var UpdateCommentsworkNotes = Class.create();
UpdateCommentsworkNotes.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getIncLastWorknotes: function() {
var recordId = this.getParameter('sysparm_id');
// Check if the record ID is provided and is not null or undefined
if (!recordId) {
gs.error("UpdateINCworkNotes.getIncLastWorknotes: No record ID (sysparm_id) provided.");
return '';
}

var grJournal = new GlideRecord("sys_journal_field");
grJournal.addEncodedQuery("element_id=" + recordId + "^element=comments^ORelement=work_notes");
grJournal.orderByDesc('sys_created_on');
grJournal.setLimit(1);
grJournal.query();

if (grJournal.next()) {
return grJournal.getValue('value');
}

return '';
},

updateCommentsLatest: function() {
var recordId = this.getParameter('sysparm_id');
var newComment = this.getParameter('sysparm_newcomment');
// Validate input parameters
if (!recordId || !newComment) {
gs.error("UpdateINCworkNotes.updateCommentsLatest: Missing required parameters (sysparm_id or sysparm_newcomment).");
return "failure: Missing parameters.";
}

// Update the latest journal entry for the incident
var grJournal = new GlideRecord("sys_journal_field");
grJournal.addEncodedQuery("element_id=" + recordId + "^element=comments^ORelement=work_notes");
grJournal.orderByDesc('sys_created_on');
grJournal.setLimit(1);
grJournal.query();

if (grJournal.next()) {
grJournal.setValue('value', newComment);
grJournal.update();
} else {
// Log if no journal field was found to update
gs.warn("UpdateINCworkNotes.updateCommentsLatest: No latest journal entry found for record ID: " + recordId);
}

var grAudit = new GlideRecord("sys_audit");
grAudit.addEncodedQuery("documentkey=" + recordId + "^fieldname=comments^ORfieldname=work_notes");
grAudit.orderByDesc('sys_created_on');
grAudit.setLimit(1);
grAudit.query();

if (grAudit.next()) {
grAudit.setValue('newvalue', newComment);
grAudit.setValue('oldvalue', '');
grAudit.update();
} else {
gs.warn("UpdateINCworkNotes.updateCommentsLatest: No latest audit entry found for record ID: " + recordId);
}

var grHistorySet = new GlideRecord("sys_history_set");
grHistorySet.addQuery("id", recordId);
grHistorySet.setLimit(1);
grHistorySet.query();

if (grHistorySet.next()) {
grHistorySet.deleteRecord();
}
},

type: 'UpdateCommentsworkNotes'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div style="display:flex; flex-direction:column;">
<textarea id='commenttext' style="width:100%; margin-bottom:10px" name="w3review" rows="4" cols="50"></textarea>
<g:dialog_buttons_ok_cancel ok_text="${gs.getMessage('Submit')}" ok_title="${gs.getMessage('Submit')}" ok="return submitComment();" ok_style_class="btn btn-primary" cancel_text="${gs.getMessage('Cancel')}" cancel_title="${gs.getMessage('Cancel')}" cancel="return closeDialog(); disable" />
</div>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
fetchLastComment();

function closeDialog() {
GlideDialogWindow.get().destroy();
return false;
}

function fetchLastComment() {
var dialogWindow = GlideDialogWindow.get();
var incidentSysId = dialogWindow.getPreference('incid');
var glideAjax = new GlideAjax('UpdateINCworkNotes');
glideAjax.addParam('sysparm_name', 'getIncLastWorknotes');
glideAjax.addParam('sysparm_id', incidentSysId);
glideAjax.getXMLAnswer(setCommentFieldValue);
}

function setCommentFieldValue(answer) {
var commentField = document.getElementById('commenttext');
if (commentField) {
commentField.value = answer || '';
}
}

function submitComment() {
var dialogWindow = GlideDialogWindow.get();
var incidentSysId = dialogWindow.getPreference('incid');
var newCommentText = document.getElementById('commenttext').value;

var glideAjax = new GlideAjax('UpdateINCworkNotes');
glideAjax.addParam('sysparm_name', 'updateCommentsLatest');
glideAjax.addParam('sysparm_id', incidentSysId);
glideAjax.addParam('sysparm_newcomment', newCommentText);

glideAjax.getXMLAnswer(handleSuccessfulSubmit);
closeDialog();
}

function handleSuccessfulSubmit(answer) {
window.location.reload();
}
Loading