- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 04:31 PM
Hi All,
I am trying to set the assigned to of a HR case after submitting from create new case in HR case management.
below is the business rule created however it is not working in scoped application.
Before Insert
function executeRule(current, previous /*null when async*/ ) {
var Cusr = gs.getUserID();
var Cag = current.assignment_group.getDisplayValue();
if (Cusr.isMemberOf(Cag)){
current.assigned_to = Cusr;
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 07:08 AM
You can use the script provide in your after-insert BR, and yes it follows best practice to use current.update() in after-insert Business rule.
Use the script below and it will work.
(function executeRule(current, previous /*null when async*/ ) {
var Cusr = gs.getUserID();
//var Cop = current.opened_by;
gs.info('the logged in user is :' +Cusr);
var Cag = current.assignment_group.getDisplayValue();
gs.info('the assignment group is :'+Cag);
if (gs.getUser().isMemberOf(current.assignment_group.getDisplayValue())){
gs.info('into my if loop');
current.assigned_to = Cusr;
current.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:35 AM
Yes what you said is right, but it has to be avoided. Because using current.update in after update will trigger again all before BRs as its a new update and it can go into recursive loop.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:42 AM
Yup I agree, and that's the reason before-insert/update is always recommended while updating the current record because current.update()is not required in it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:07 PM
Hi,
Try this code.
function executeRule(current, previous /*null when async*/ ) {
var Cag = current.assignment_group.getDisplayValue();
if (gs.getUser().isMemberOf(Cag)){
current.assigned_to = gs.getUserID();
}
})(current, previous);
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:19 PM
Hi
Tried the code you provide but did not work , assigned to is still blank.
please let where am I doing wrong.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:21 PM
Hi,
If you are running this in scoped application, then instead of isMemberOf, use isMemberOfForScopedApp and check once.
Also place logs inside if condtion to check if its entering the if condition or not.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP