Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions Client-Side Components/UI Pages/Edit Last WorkNotes/Client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function callme() {
var dialog = new GlideModal("edit_comment_inc");

//Set the dialog title
dialog.setTitle('Edit last comment');
dialog.setPreference('incid', g_form.getUniqueValue());
//Set the dialog width
dialog.setWidth(550);

//Display the modal
dialog.render();
}
17 changes: 17 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,17 @@
Edit Last Entered Work Notes

This UI action is built specifically to edit the last entered work notes by the user in incident form or 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 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.

Key actions:
sys_journal_field :
list.value = newcomment; // update the new comment

sys_audit:
list1.newvalue = newcomment
list1.oldvalue = ''; // clear the old value and update the new value

sys_history_set:
Delete the history record associate with the incident record
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var UpdateINCworkNotes = Class.create();
UpdateINCworkNotes.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getIncLastWorknotes: function() {
var id = this.getParameter('sysparm_id');
// var table = 'incident';
var list = new GlideRecord("sys_journal_field");
list.addEncodedQuery("element_id=" + id + "^element=comments^ORelement=work_notes");

list.orderByDesc('sys_created_on');
list.setLimit(1);
list.query();
list.next();
return list.value.toString()
},


updateCommentsLatest: function() {
var id = this.getParameter('sysparm_id');
var newcomment = this.getParameter('sysparm_newcomment');
// var table = 'incident';
var list = new GlideRecord("sys_journal_field");
list.addEncodedQuery("element_id=" + id + "^element=comments^ORelement=work_notes");
list.orderByDesc('sys_created_on');
list.setLimit(1);
list.query();
list.next();
list.value = newcomment;
list.update();

var list1 = new GlideRecord("sys_audit");
list1.addEncodedQuery("documentkey=" + id + "^fieldname=comments^ORfieldname=work_notes");
list1.setLimit(1);
list1.orderByDesc('sys_created_on');
list1.query();
if (list1.next()) {
list1.newvalue = newcomment
list1.oldvalue = '';
list1.update();
}

var list3 = new GlideRecord("sys_history_set");
list3.addEncodedQuery("id=" + id);
list3.setLimit(1);
list3.query();
if (list3.next()) {
list3.deleteRecord();
}
window.location.reload();
},

type: 'UpdateINCworkNotes'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?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 onSubmit();" ok_style_class="btn btn-primary" cancel_text="${gs.getMessage('Cancel')}" cancel_title="${gs.getMessage('Cancel')}" cancel="return onCancel(); disable" />
</div>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function onCancel() {
GlideDialogWindow.get().destroy();
return false;
}
fetchlastcomment();

function fetchlastcomment() {
var gdw = GlideDialogWindow.get(); // attempting to get the sys_id value
var sys_id = gdw.getPreference('incid'); // attempting to get the sys_id value
var ga = new GlideAjax('global.UpdateINCworkNotes');
ga.addParam('sysparm_name', 'getIncLastWorknotes');
ga.addParam('sysparm_id', sys_id);

ga.getXMLAnswer(callback);

function callback(answer) {
if (answer) {
document.getElementById('commenttext').value = answer;
} else {
document.getElementById('commenttext').value = '';
}
}

}

function onSubmit() {
var gdw = GlideDialogWindow.get(); // attempting to get the sys_id value
var sys_id = gdw.getPreference('incid'); // attempting to get the sys_id value
var ga = new GlideAjax('global.UpdateINCworkNotes');
ga.addParam('sysparm_name', 'updateCommentsLatest');
ga.addParam('sysparm_id', sys_id);
ga.addParam('sysparm_newcomment', document.getElementById('commenttext').value);

ga.getXMLAnswer(callback);

function callback(answer) {
window.location.reload();
}
GlideDialogWindow.get().destroy();
return false;
}
Loading