- 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 06:17 AM
Hi
I am trying the below script .I am getting all logs but the assigned to is not getting set .
(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, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 06:57 AM
Hi,
I suspect that there is some validation which is stopping the user being assigned.
try setting a hardcoded sys_id of the user jsut to confirm if its being set or not. If that is also not getting set, then it means there could be either anothe BR which might be restricting it or any ui policy or client script which is setting the assigment_to field to empty after loaded.
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 08:20 AM
Hi,
Did you try the suggestion that i have given above?
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 08:37 AM
Hi
This is my final script which is working to set the assigned to and source on the HR Case.
I am using the current.update() in the after business rule with out which I am able to do it .
Please suggest if this will cause issues
(function executeRule(current, previous /*null when async*/ ) {
var Cusr = gs.getUserID();
var Cst = current.state;
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');
if (Cst == 1) {
current.contact_type = 'phone';
current.assigned_to = Cop;
current.update();
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:55 AM
For being safer side use the below script just before the current.update()
current.setWorkflow(false);
Note:- Using setWorkflow(false) will restrict the auditing of any insert or update of record.