Restrict additional comments to the users from activities

Narayana RC
Tera Contributor

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.

 

NarayanaRC_0-1717579901817.png

 

 

Regards

NC

4 REPLIES 4

Jaap
Tera Expert

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




Was my comment helpful? Please mark as such! 🙂

Narayana RC
Tera Contributor

@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

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);
Was my comment helpful? Please mark as such! 🙂

Narayana RC
Tera Contributor

sorry... its not working as expected