Business Rule/Script to Change Assignment Group If Incident for Same User Closed Recently
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 03:35 PM
Hi Team,
I recently created a business rule in our Test environment that we're experiencing issues with, I'm hoping someone can assist. The purpose of this business rule is to check if the Employee Number (u_reference_1 field) in newly opened incidents, previously had any incidents closed/resolved within 48 hours under the two specific assignment groups under the same Employee Number. For example, employee "John Doe" opens a new incident in the assignment group "Total Rewards", the business rule will check if employee "John Doe" had a closed/resolved incident (within 48 hours) under the assignment groups of "Talentcycle" or "Talentcycle Admin". If he does, the incident will automatically assign to the "Technology Operations" assignment group. If not, the assignment group will remain the same.
Upon testing the business rule, it doesn't appear to be working as expected as it's assigning the incidents to the "Technology Operations" assignment group, even if the user didn't have an incident closed recently with the "Talentcycle" groups:
var gr = new GlideRecord('hr_case');
gr.addEncodedQuery("assignment_group=eeb4dbe3db65491065e6450b139619c8^ORassignment_group=6eb4dbe3db65491065e6450b139619af^stateIN20,3^closed_atONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^ORclosed_atONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()^ORsys_updated_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^ORsys_updated_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()");
gr.query();
{
if (current.u_reference_1 == gr.u_reference_1);
current.assignment_group = '6ff24be8db44445018e930cf9d961946';
}
Any assistance would be greatly appreciated.
Thank you,
Jamie
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 05:09 PM
Hi, I think your issue is that you are not using next() in your query and without the encapsulation your 'if' condition is always run. Also as as you only need to validate if 1 record is returned you can use setLimit(1) to limit the result form the query. Perhaps try a syntax like this, note I didn't test your encoded query.
var gr = new GlideRecord('hr_case');
gr.addEncodedQuery("assignment_group=eeb4dbe3db65491065e6450b139619c8^ORassignment_group=6eb4dbe3db65491065e6450b139619af^stateIN20,3^closed_atONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^ORclosed_atONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()^ORsys_updated_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^ORsys_updated_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()");
gr.setLimit(1);
gr.query();
if(gr.next()) {
if(current.u_reference_1 == gr.u_reference_1) {
current.assignment_group = '6ff24be8db44445018e930cf9d961946';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 06:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 05:12 PM
Hi Jamie,
Couple of issues.
1. var gr = new GlideRecord('hr_case'); are you sure with table name. I guess it should be sn_hr_core_case
2. Add if(gr.next()) just after gr.query(); line
3. If Business rule is exeucting After you need to use current.update(); just before last line i.e. }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2022 06:10 PM
Thanks Jaspal! I updated the BR with your suggestion (and Tony's above) and it worked... but only for one employee that I was testing with. I tried another test employee and the BR didn't run properly. Any ideas? Thanks again.
Do I need to make any additional amendments below?
