Record producer to create HR case and Incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 11:27 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 11:38 PM
To create incidents and HR cases from the same record producer in ServiceNow based on priority, you can use Business Rules
Identify Priority Field: Ensure that you have a Priority field on your record producer form that users can select.
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.
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 12:23 AM
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
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();
}
I created a variable called Priority and on the basis of that variable I'm doing insertion
Result
Record created in User table
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 12:59 AM
In HR case scenario it should also attached to specific HR service as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 01:23 AM
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