- 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);
Thanks and Regards,
Alok
- 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);
Thanks and Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 07:24 AM
For before script, you don't need current.update as its already running on current and update happens internally.
For after insert, i think current.update() does not work as its already inserted. you have to gliderecord and do update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 07:38 AM
yes for before-insert/update current.update() is not required because it's going to update. It work but it will work but It's also not a good practice to use current.update()
For after insert/update current.update() works and it's required to update any field on any existing record. Gliderecord and update is required for the field update on other table and records.
Thanks and Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:20 AM
Yes, correct. As per this link, it is not a recommended practice to use current.update() in before or after BR.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0715782
Mark the comment as helpful if it helps.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:27 AM
Yes current.update() is not recommended to be used in before-insert/update BR.
But to update current record in After- Insert/Update BR you have to use current.update() because it's already updated and if current.update() is not used it will not update current record.
Thanks and Regards,
Alok
