Capture the deletion of any Related list record in Activity filter at the case level

Darshana2
Tera Contributor

I want to capture and view the details of when any related list record is deleted from the case.

I need system to log the user who deleted the record, the date/time stamp of the deletion and what type of record was deleted (Allegations,Corrective Actions) etc. to the Activities filter that is stored under the Comments and Work Notes tab on the case.

2 REPLIES 2

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Darshana2 ,
I trust you are doing great.

  1. Create a new business rule:

    • Navigate to "Business Rules" in the ServiceNow Studio or Development menu.
    • Click on "New" to create a new business rule.
    • Provide a suitable name and description for the rule.
  2. Set the conditions for the business rule:

    • In the "When to run" section, choose the appropriate condition that matches when a related list record is deleted from a case. For example, you can use "after" delete on the related list table.
  3. Define the actions for the business rule:

    • In the "Advanced" tab of the business rule, write a script to log the necessary information to the Activities filter under the Comments and Work Notes tab on the case.
(function executeRule(current, previous /*, gs*/) {
   var caseSysID = current.getValue('parent'); // Get the case sys_id
   var caseRecord = new GlideRecord('table_name_of_case'); // Replace 'table_name_of_case' with the actual table name of the case
   if (caseRecord.get(caseSysID)) {
      var deletedRecordType = 'Allegations'; // Replace with the appropriate record type
      var deletedBy = gs.getUser().getDisplayName();
      var deletionTimestamp = gs.nowDateTime();

      var activities = caseRecord.getValue('activity_notes') || '';
      var deletionDetails = 'Deleted ' + deletedRecordType + ' record on ' + deletionTimestamp + ' by ' + deletedBy;
      activities += '\n' + deletionDetails;
      caseRecord.setValue('activity_notes', activities);
      caseRecord.update();
   }
})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Darshana2
Tera Contributor

from where you have given  field value 'activity_notes'