diff --git a/Client-Side Components/UI Pages/Edit Last WorkNotes/Client.js b/Client-Side Components/UI Pages/Edit Last WorkNotes/Client.js new file mode 100644 index 0000000000..6ffd60d2e4 --- /dev/null +++ b/Client-Side Components/UI Pages/Edit Last WorkNotes/Client.js @@ -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(); +} diff --git a/Client-Side Components/UI Pages/Edit Last WorkNotes/README.md b/Client-Side Components/UI Pages/Edit Last WorkNotes/README.md new file mode 100644 index 0000000000..7d90436328 --- /dev/null +++ b/Client-Side Components/UI Pages/Edit Last WorkNotes/README.md @@ -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 diff --git a/Client-Side Components/UI Pages/Edit Last WorkNotes/scriptinclude.js b/Client-Side Components/UI Pages/Edit Last WorkNotes/scriptinclude.js new file mode 100644 index 0000000000..fdf685413f --- /dev/null +++ b/Client-Side Components/UI Pages/Edit Last WorkNotes/scriptinclude.js @@ -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' +}); diff --git a/Client-Side Components/UI Pages/Edit Last WorkNotes/uipage_client.html b/Client-Side Components/UI Pages/Edit Last WorkNotes/uipage_client.html new file mode 100644 index 0000000000..a08c4f8498 --- /dev/null +++ b/Client-Side Components/UI Pages/Edit Last WorkNotes/uipage_client.html @@ -0,0 +1,9 @@ + + +
+ + +
+
diff --git a/Client-Side Components/UI Pages/Edit Last WorkNotes/uipage_clientcode.js b/Client-Side Components/UI Pages/Edit Last WorkNotes/uipage_clientcode.js new file mode 100644 index 0000000000..48995ca24c --- /dev/null +++ b/Client-Side Components/UI Pages/Edit Last WorkNotes/uipage_clientcode.js @@ -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; +}