
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2019 03:41 AM
Morning,
We have a catalog item with a basic create task workflow that generates a case record. However, we have found that we cannot define the assignment group and the assignee from 'Populate task variables' in the create task record, as the assignee was constantly defaulting to the requestor.
To get around this, we created a business rule on the case table with the action to set field values 'assignment group' and 'assigned to' to the values required. Not good hardcoding a single user into a BR, but it works.
The problem comes when that user leaves the organisation or moves department, and we have not updated the rule. For example, if the assigned to is still a valid user but now only has snc_internal role, the case is still assigned to them as per the business rule actions. So I assume the solution is to query whether the user is still a member of that group.
I have tried adding an advanced script to the BR as follows
(function executeRule(current, previous /*null when async*/) {
var currtech = g_form.getValue('assigned_to');
var grplist = new GlideRecord('sys_user_grmember'); //this table lists all group-member associations
grplist.addQuery('group',newValue);
grplist.addQuery('user',currtech);
grplist.query();
if (!grplist.hasNext()) //clear technician if not in the newly assigned group
g_form.setValue('assigned_to','');
})(current, previous);
I have also tried using on load and on submit client scripts based on the same code, but nothing seems to stop the case being populated with the defined user.
Is there any way to define the 'assigned to' value and if they are still a member of the 'assignment group' then cretae case, but if they are not a current member of the 'assignment group' then still create the case but leave the 'assigned to' empty?? (note that in the absence of any scripting, the business rule will create the case but leave the 'assigned to' empty if the user record is deleted)
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2019 04:01 AM
Business Rules work on server side on saving the data to the database. So one can't use g_form and newValue existing in onChange Client Script.
Instead of that you should use current variable, which will be set before BR be started and which is GlideRecord filled with current record data. If you need to remove value from some field or to set NULL, then you should use a strange syntax in server script: current.assigned_to = "NULL"; (see here). So the code of business rule can be fixed to the following
(function executeRule(current, previous /*null when async*/) {
var grplist = new GlideRecord('sys_user_grmember'); //this table lists all group-member associations
grplist.addQuery('group', current.assignment_group);
grplist.addQuery('user', current.assigned_to);
grplist.query();
if (!grplist.hasNext()) { // clear technician if not in the newly assigned group
current.assigned_to = "NULL";
}
})(current, previous);
Additionally, you should define good condition on the business rule to prevent unneeded execution of the code. For example, one should run the code only if both assignment_group and assigned_to are not empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2019 04:01 AM
Business Rules work on server side on saving the data to the database. So one can't use g_form and newValue existing in onChange Client Script.
Instead of that you should use current variable, which will be set before BR be started and which is GlideRecord filled with current record data. If you need to remove value from some field or to set NULL, then you should use a strange syntax in server script: current.assigned_to = "NULL"; (see here). So the code of business rule can be fixed to the following
(function executeRule(current, previous /*null when async*/) {
var grplist = new GlideRecord('sys_user_grmember'); //this table lists all group-member associations
grplist.addQuery('group', current.assignment_group);
grplist.addQuery('user', current.assigned_to);
grplist.query();
if (!grplist.hasNext()) { // clear technician if not in the newly assigned group
current.assigned_to = "NULL";
}
})(current, previous);
Additionally, you should define good condition on the business rule to prevent unneeded execution of the code. For example, one should run the code only if both assignment_group and assigned_to are not empty.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2019 04:22 AM
Thanks Oleg, code works exactly as I wanted. I will also take a look at additional null controls you advise.