hrtest

nikhitha24
Tera Guru
 
7 REPLIES 7

@nikhitha24 

You can write an onBefore Update business rule on sn_hr_core_case table with condition HR Service is Travel AND State Changes to Closed Complete. In the business rule script, you can create a new HR case as follows.

 

Please update the aforementioned script as follows.

var hrCase = new GlideRecord('sn_hr_core_case');
        hrCase.initialize();

        // Set mandatory and required fields
        hrCase.short_description = "Example HR Case Created via Script";
        hrCase.description = "This HR case is created via a script for demonstration purposes.";
        hrCase.opened_for = current.opened_for+'';
        hrCase.subject_person = current.subject_person+'';
        hrCase. subject_person_hr_profile = current. subject_person_hr_profile;+''
        hrCase.hr_service = "92c63f19c0a8016401c5a33be04be552"; // Replace with the sys_id of the HR service
        var hrServiceName = current.hr_service.name; // Assuming 'name' is the HR service name field
        
        if (hrServiceName == 'Travel') {
            current.u_enquiry_type = 'New Starters'; // Update enquiry type to New Starters
        } else {
            current.u_enquiry_type = 'New Hire'; // Update enquiry type to New Hire
        }

        // Insert the record into the HR case table
        var caseSysId = hrCase.insert();
         
        if (caseSysId) {
            gs.info("HR Case created successfully with sys_id: " + caseSysId);
        } else {
            gs.error("Failed to create HR Case.");
        }

Please mark the response accepted solution if it addresses your question.

Seema Hegde
ServiceNow Employee
ServiceNow Employee

Have you tried using Service Activities? This will be simpler and configuration driven and not require any scripting.

 

In your initial HR Service definition, set the Fulfillment type to "Service Activity". This should display the Service activities related list. 

SeemaHegde_0-1732655458443.png

 

Create a new service activity of type "Child HR Service", and set your required HR Service.

SeemaHegde_1-1732655989600.png

 

This is simpler and configuration driven, and does not require any additional scripting.

 

 

 

Hi @Seema Hegde 

Where can we mention the condition such as State is Close Complete of parent HR case?