Comments for Knowledge Records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2023 03:51 AM
Hello Community,
We are working on the MY Tasks page in EC Portal where displaying the Approval records which are requested for RITM, Change, HR, Knowledge Records. At the bottom of the Approval record we are displaying a comment box above the Approve/Reject button for the user to write the comments when approved/rejected. I'm using the same OOB 'Todos Approval Actions' widget for all the records. All the approval records are getting the comment box displayed except the Knowledge Records.
When I checked in logs , data.requireRejectionComment is returning false for knowledge articles, where other approval records is having true . Please Let me know Where I need to check to get the comment box for knowledge articles as well. In the instance there is comment mandatory for rejection approvals of knowledge as well.
Below is the server script code in the widget.
(function() {
data.CONST = {
i18n: {
PLACEHOLDER_MESSAGE: gs.getMessage("If you are rejecting the request, provide the reason here."),
REJECT_MODAL_TITLE: gs.getMessage("Reject Request"),
REJECT_MODAL_MESSAGE: gs.getMessage("Please provide a reason for rejecting the request"),
REJECT_MODAL_CANCEL: gs.getMessage("Cancel"),
REJECT_MODAL_SUBMIT: gs.getMessage("Reject Request")
},
ACTION: "updateApprovals",
REJECT_STATE: "rejected",
APPROVED_STATE: "approved",
REQUESTED_STATE: "requested",
APPROVAL_TABLE: "sysapproval_approver"
};
var approvalGr = null;
var commentGr = null;
data.isApprover = false;
if (input && input.action === data.CONST.ACTION) {
approvalGr = getTargetRecord(input.approvalId, data.CONST.APPROVAL_TABLE);
data.isApprover = approvalGr.state != 'undefined' && approvalGr.state.canWrite();
if (data.isApprover) {
commentGr = getTargetRecord(input.commentId, input.commentTable);
data.isPosted = false;
data.requireRejectionComment = checkRejectionCommentRequired(commentGr);
data.useCommentBox = input.useCommentBox && data.requireRejectionComment;
if (updateApprovalAndComment(input.request) && commentGr)
getPostApprovalInfo();
}
} else if (options && options.sysId && options.commentId && options.commentTable) {
approvalGr = getTargetRecord(options.sysId, data.CONST.APPROVAL_TABLE);
data.isApprover = approvalGr.state != 'undefined' && approvalGr.state.canWrite();
if (data.isApprover) {
commentGr = getTargetRecord(options.commentId, options.commentTable);
data.isPosted = false;
data.approvalId = options.sysId;
data.commentId = options.commentId;
data.commentTable = options.commentTable;
data.requireRejectionComment = checkRejectionCommentRequired(commentGr);
data.useCommentBox = options.useCommentBox && data.requireRejectionComment;
if (approvalGr && approvalGr.state.toString() !== data.CONST.REQUESTED_STATE) {
data.isPosted = true;
if (commentGr) {
getPostApprovalInfo();
}
}
}
}
/**
* Gets the approval record given a sys id
* @Param {String} sysId The sys_id of the approval record
* @Param {String} tableName The name of the record's table
* @return {GlideRecord} A glide record with the approval
*/
function getTargetRecord(sysId, tableName) {
var targetGr = new GlideRecord(tableName);
data.shortDescription = "";
if (targetGr.get(sysId) && targetGr.canWrite())
return targetGr;
else {
gs.error("Could not find approval record");
return null;
}
}
/**
* Checks user write permissions to determine whether or not a rejection comment
* is required from them to update the approval state
* @Param {GlideRecord} activityStreamGr The record to check if comments can be written
* @return {Boolean} True if comment is required, false otherwise
*/
function checkRejectionCommentRequired(activityStreamGr) {
if (!activityStreamGr) {
gs.error("Could not find Activity Stream record");
return false;
}
return typeof activityStreamGr.comments != 'undefined' && activityStreamGr.comments.canWrite();
}
/**
* Updates the state of the approval
* @Param {Object} request An object describing the update request
* @return {Boolean} Returns true on successful update, false otherwise
*/
function updateApprovalAndComment(request) {
if (request.state === data.CONST.REJECT_STATE) {
if (data.requireRejectionComment && data.useCommentBox && !request.comments) {
gs.addErrorMessage(gs.getMessage("Provide the reason you are rejecting the request in the comments field."));
return false;
} else if (request.comments) {
commentGr.comments = gs.getMessage('Reason for rejection: {0}', request.comments);
commentGr.update();
}
var displayMessage = gs.getMessage("You rejected this request");
} else if (request.state === data.CONST.APPROVED_STATE) {
if (request.comments) {
commentGr.comments = gs.getMessage('Reason for approval: {0}', request.comments);
commentGr.update();
}
var displayMessage = gs.getMessage("You approved this request");
} else
return false;
// Set state and update
approvalGr.state = request.state;
if (approvalGr.update()) {
gs.addInfoMessage(displayMessage);
data.isPosted = true;
return true;
} else {
gs.addErrorMessage(gs.getMessage("Could not update approval record."));
return false;
}
}
/**
* Sets the last comments and timestamp of the approval to data
*/
function getPostApprovalInfo() {
data.caption = gs.getMessage("The request was {0}", approvalGr.state.getDisplayValue());
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
if (commentGr.comments) {
var journalEntryComment = commentGr.comments.getJournalEntry(1);
data.comment = journalEntryComment.replace(dateRE, '').toString();
}
data.timeStamp = approvalGr.sys_updated_on.toString();
}
})();