Restrict additional comments to the users from activities
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 02:32 AM
Hello Experts,
is it possible to restrict rejected comments added in the case activities do not visible to the end users? this comments added by approver and copied to the case activities.
Regards
NC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 02:49 AM
Hi @Narayana RC ,
I would say yes. You can create a before business rule to check whether the state has been changed to rejected to not add the comments. Submit the business rule to the case activities table. Such a script would look something like this:
(function executeRule(current, previous /*previous*/) {
// Check if the comment is being added by an approver
var approverRole = 'approver'; // Replace with the actual role name of your approver
var currentUser = gs.getUser();
if (currentUser.hasRole(approverRole)) {
// Check if the case associated with the activity is rejected
var caseSysID = current.case.sys_id; // Assuming case is a reference field on the case activity table
var caseGR = new GlideRecord('case'); // Replace 'case' with the actual table name of your case
if (caseGR.get(caseSysID)) {
var caseStatus = caseGR.getValue('state'); // Assuming 'state' is the field representing case status
if (caseStatus == 'rejected') {
// If case is rejected, do not allow the comment to be added
gs.addErrorMessage('You are not allowed to add comments to rejected cases.');
current.setAbort(true); // Abort the insertion of the comment
}
}
}
})(current, previous);
Hope this answers your question.
Regards,
Jaap
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 02:54 AM
@Jaap sorry for the miscommunication , the requirement is approver rejected case and added comments in approval record, these comments added in respective HR Case. I want to hide this comments from activities for user.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 03:14 AM
Try this:
(function executeRule(current, previous /*previous*/) {
// Check if the approval record is rejected and comments are added
if (current.state == 'rejected' && current.comments) {
// Get the corresponding HR Case record
var hrCase = new GlideRecord('HR_CASE_TABLE_NAME'); // Replace 'HR_CASE_TABLE_NAME' with the actual table name for HR Cases
if (hrCase.get(current.hr_case)) {
// Add comments to the HR Case record
hrCase.comments += "\n" + current.comments;
hrCase.update();
// Hide comments from the activity stream for users
var activityStream = new GlideRecord('sys_journal_field');
activityStream.addQuery('element_id', hrCase.sys_id);
activityStream.addQuery('element', 'comments');
activityStream.query();
while (activityStream.next()) {
activityStream.setWorkflow(false); // To avoid triggering other business rules
activityStream.visible = false;
activityStream.update();
}
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 09:44 PM
sorry... its not working as expected