- 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:59 AM
Any reason, why you are not doing this in before insert BR? Doing so, you don't need current.update() as well.
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-07-2020 09:07 AM
Yes, keep the working script as a Workaround and try with
Before
Insert: True
Update: True
Script:
function executeRule(current, previous /*null when async*/ ) {
if(gs.getUser().isMemberOf(current.assignment_group.name.toString()))
current.assigned_to=gs.getUserID();
}
If the above works then please don't forget to mark correct and helpful based on the Impact.
Else, you can keep your workaround with updating setWorkflow(false) just above the current.update().
Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 11:23 AM
Thanks Alok,
I had to go with after insert business rule as the before insert was not working for my use case. I am using current.setWorkflow(false)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 12:04 PM
Thanks for all your suggestions
Yes, there already a script OOB to set the Source on the HR case when case created from Portal . Now I am trying to set the Source and assigned to for HRcases when created from native view .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 12:17 PM
Okay. If my comment(s) has helped you to achieve the problem, kindly mark them as helpful.
Regards,
Asif
2020 ServiceNow Community MVP