Record producer to create HR case and Incident.

Vijay Baokar
Kilo Sage

Hi Folks,

 

What is the best way to create incident and HR case from same record producer based on priority like if Priority is High then HR case to be created where as for Low and Medium, incident should be created.

 

Considering we have global and HR app scope.

4 REPLIES 4

Maddysunil
Kilo Sage

@Vijay Baokar 

To create incidents and HR cases from the same record producer in ServiceNow based on priority, you can use Business Rules

  1. Identify Priority Field: Ensure that you have a Priority field on your record producer form that users can select.

  2. Create Business Rules: Write a Business Rule that triggers when a record is inserted or updated. This Business Rule should check the priority field value and decide whether to create an incident or an HR case accordingly.

  3. Create Incidents and HR Cases: Depending on the priority selected, create incidents or HR cases.

If you're working with tables from different scopes (e.g., incident table in the global scope and HR case table in a scoped app), you'll need to handle scope issues carefully.

Use Script Includes: Script Includes are scoped by default, but they can be marked as global to be accessible from other scopes. You can create a Script Include in your scoped HR app that contains the functions for creating HR cases. This Script Include should be marked as global. Below is the sample script

 

 

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

    // Check if the priority field is not empty
    if (current.priority) {
        
        // Determine the priority value
        var priorityValue = current.priority.getDisplayValue();

        // Check priority value and create either Incident or HR Case
        if (priorityValue == '1') { // High priority
            createHRCase(current);
        } else { // Medium or Low priority
            createIncident(current);
        }
    }

})(current, previous);

// Function to create an HR Case (from Scoped App)
function createHRCase(current) {
    var hrCase = new global.HRCaseUtils(); // Assuming HRCaseUtils is a global Script Include in your scoped HR app
    hrCase.createHRCase(current);
}

// Function to create an Incident (from Global Scope)
function createIncident(current) {
    var incident = new GlideRecord('incident');
    incident.initialize();
    // Set Incident fields based on the current record data
    // For example: incident.short_description = current.short_description;
    incident.insert();
}

 

  

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Community Alums
Not applicable

Hi @Vijay Baokar ,

I tried your problem in my PDI and it works for me, you can refer below steps for reference 

I don't have HR Case table so I did it on incident, change and user table 

SarthakKashya2_0-1713251956109.png

Add script given below

gs.log("Chcekc Priority = " + producer.priority);
if(producer.priority == 'p_two'){
	var gr = new GlideRecord('sys_user');
	gr.initialize();
	gr.first_name = 'User RP';
	var id = gr.insert();
}else{
	var chGr = new GlideRecord('change_request');
	chGr.initialize();
	chGr.description = 'RP Description';
	chGr.insert();
}

SarthakKashya2_1-1713252002697.png

 

I created a variable called Priority and on the basis of that variable I'm doing insertion 

SarthakKashya2_2-1713252046116.png

SarthakKashya2_3-1713252088036.png

 

Result

 

 

SarthakKashya2_4-1713252119452.png

Record created in User table 

SarthakKashya2_5-1713252144610.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

 

 

 

In HR case scenario it should also attached to specific HR service as well.

Community Alums
Not applicable

Hi @Vijay Baokar ,

You mean it saves as a reference of any HR service? 

You can give like : 

gr.<fieldName> = <sys_id of HR Service>;

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak