- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 11:11 PM - edited 07-19-2023 11:25 PM
Hi
Created a Business rule on incident table, where it should insert/update the records based on assignment group and active field.
And it should allow maximum 5 records with same assignment group, if more than that it should abort the action.
BR will trigger on insert/ update operation
Script:
It's working as expected on Insert operation, but
Update Operation - when record count is 5 if we update any fields ( expect AG) on the incident form it's not allowing ( not updating).
Note: If recount count is 4 or less than that no issue it's updating
Please suggest on this
Thanks!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 11:58 PM
Thanks @Pavankumar_1 for the response, We got the solution for the above issue
Need to include the addQuery( 'sys_id', '!=' ,current.sys_id); it will update the record with out any error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 11:26 PM
Hi @Charan123 ,
On your before business rule you need to change the if condition like if count greater than 5 then need to abort the action.
Not sure why you have given 15 it should be > =5 like below.
var recordCount;
var ga = new GlideAggregate('incident');
ga.addQuery('active', true);
ga.addQuery('assignment_group', current.getValue('assignment_group'));
ga.addAggregate('count');
ga.query();
if (ga.next()) {
recordCount = ga.getAggregate('count');
}
if (recordCount >= 5) { //if we have 5 incidents with current asignment group then it should stop action.
gs.addErrorMessage('Maximum 5 record allowed per Assignment group'));
current.setAbortAction(true);
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 11:58 PM
Thanks @Pavankumar_1 for the response, We got the solution for the above issue
Need to include the addQuery( 'sys_id', '!=' ,current.sys_id); it will update the record with out any error.