HR case

kali
Tera Contributor

Hi All,

 

Is there any way to automate a hr case creation , such that when parent case is closed complete and user comments on the parent case then system should create a new case. Thanks in advance

5 REPLIES 5

John Zhang1
Kilo Patron
Kilo Patron

Hi Kali,  I know you want to create new case when parent is closed after user comments.  Do you want to create another parent case?  Can you give's more information?

kali
Tera Contributor

Hi John,

When a parent case is closed and complete and a additional comment is put in the case . Then a child case should be created with same details that of parent, attachment also needs to be copied from parent case to child case

If I understand your query correctly, you could try the following.

 

To create a script in ServiceNow that automatically creates a child case when a parent case is closed and a comment is added and also copies attachments from the parent case to the child case, you can use a Business Rule. Here's a step-by-step guide on how to achieve this:

 

Navigate to "System Definition" > "Business Rules" in your ServiceNow instance.

 

Click on "New" to create a new Business Rule.

 

Fill out the form with the following details:

 

Name: Provide a unique name for your Business Rule, e.g., "Create Child Case on Parent Closure."

Table: Set it to "Incident" (or the table you are working with).

Order: You can leave this as the default value (e.g., 1000).

When to run: Set this to "Async."

In the "Advanced" tab of the Business Rule form, enter the script logic.

 

Here's an example script:

 

Screenshot 2023-09-04 at 14.29.04.png

 

This script checks if the current record is a parent case (parent field is empty) and if it's in a closed state (incident_state = 6). If these conditions are met, it creates a new child case, copies relevant details from the parent case, adds the additional comment from the parent case, and copies attachments.

  1. Save the Business Rule.

Now, whenever a parent case is closed with an additional comment, a child case will be automatically created with the same details, including attachments, and the additional comment from the parent case will be included in the child case's comments.

 

Good Luck,

 

James

Sandeep Rajput
Tera Patron
Tera Patron

@kali You can choose to create a business rule on sn_hr_core_case as follows.

 

Screenshot 2023-09-04 at 11.26.56 PM.png

Screenshot 2023-09-04 at 11.25.48 PM.png

 

Here is the business rule script.

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var childHRCase = new GlideRecord('sn_hr_core_case');
    childHRCase.initialize();
    childHRCase.short_description = current.short_description + '';
    childHRCase.description = current.description + '';
    //Similarly copy other fields
    var childHRSysID = childHRCase.insert();
    //Copy attachments from parent to child.
    if (current.hasAttachments()) {
        var attachment = new GlideSysAttachment();
        var copiedAttachments = attachment.copy('sn_hr_core_case', current.sys_id, 'sn_hr_core_case', childHRSysID);
    }

})(current, previous);

Hope this helps.