can a workflow update the case (incident) activity?

MichaelZischeck
Kilo Sage

We use the Case management for our customers.

Upone adding a "parent" i'd like to mark the parent as "Problem case". 

This works just fine with a workflow. 

BUT: i'd like the Activities (especially Field changes) to be updated with the appropriate field change on the parent case.

 

How can I achieve this?

1 ACCEPTED SOLUTION

MichaelZischeck
Kilo Sage

the solution was quite simple: 

in the normal GUI (not workspace) I can configure which fields are displayed in "field changes"... so I added the field in question (category) and voilà

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

Hi,

Can you try following code in BR on the table you’re using for your cases.

Script: 

 

You add a trigger condition as field_name is changes.

 

(function executeRule(current, previous /*null when async*/) {
// Check if the Parent Case exists
if (current.parent) {
  var parentCase = new GlideRecord('case');
if (parentCase.get(current.parent)) {
  var activity = new GlideRecord('case_activity');
  activity.initialize();
  activity.case = parentCase.sys_id;
  activity.activity_type = 'Field Change'; // Set type to Field Change or any other type
  activity.field_name = current.field_name; // Field that was changed
  activity.old_value = previous.field_name;
  activity.new_value = current.field_name;
activity.insert();
}
}
})(current, previous);

Ankur Bawiskar
Tera Patron
Tera Patron

@MichaelZischeck 

you can sync the fields using after update BR on Case table

Condition: Field1 Changes AND Parent is not empty

// your code to copy field values

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@MichaelZischeck 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Runjay Patel
Giga Sage

Hi @MichaelZischeck ,

 

You can create before BR and use below script.

(function executeRule(current, previous /*null when async*/) {
    if (!current.parent) {
        return; // Exit if there's no parent case
    }

    var parentCase = new GlideRecord('sn_customerservice_case');
    if (parentCase.get(current.parent)) {
        var changedFields = [];
        
        // Compare fields and log changes
        if (current.state != previous.state) {
            changedFields.push("State changed from " + previous.state.getDisplayValue() + " to " + current.state.getDisplayValue());
            parentCase.state = current.state; // Sync state
        }

        if (current.assignment_group != previous.assignment_group) {
            changedFields.push("Assignment Group changed from " + previous.assignment_group.getDisplayValue() + " to " + current.assignment_group.getDisplayValue());
            parentCase.assignment_group = current.assignment_group;
        }

        if (changedFields.length > 0) {
            var updateMessage = "Updated due to child case changes:\n" + changedFields.join("\n");
            parentCase.work_notes = updateMessage;
            parentCase.update();
        }
    }
})(current, previous);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------