- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 10:02 AM
Good afternoon!
I am trying to set up a business rule so that when the "Assignment Group" OR "Assigned To" is changed on the Catalog Task, the related Request Item and Request are updated with the same group or technician. Currently, when I updated the assignment group or the assigned to user, nothing changes on the RITM or the REQ records. I'm hoping someone can identify what's incorrect in my script. Thanks!
I have set up the following.
Business Rule:
Table: Catalog Task [sc_task}
When to run: after update
Condition: Assigned to changes OR Assignment Group Changes
Script:
(function executeRule(current, previous /*, display*/) {
// Check if the 'assigned_to' field has been changed
if (current.assignment_group.changes() || current.assigned_to.changes()) {
// Get the Requested Item associated with the Catalog Task
var requestedItem = new GlideRecord('sc_req_item');
if (requestedItem.get(current.cat_item)) {
// Update the Requested Item's assigned_to with the Catalog Task's assigned_to
requestedItem.assigned_to = current.assigned_to;
requestedItem.update();
}
// Get the Request associated with the Catalog Task
var request = new GlideRecord('sc_request');
if (request.get(current.request)) {
// Update the Request's assigned_to with the Catalog Task's assigned_to
request.assigned_to = current.assigned_to;
request.update();
}
}
})(current, previous);
Screenshots:
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 11:35 AM
Since you have the filter conditions, there's no need to repeat the same with your script wrapped in an if statement, but it's not really hurting anything. Since this rule is running on the sc_task table, 'current' refers to the sc_task record that was just updated. The cat_item field references the Catalog Item that the RITM is associated with, so you'll want to use request_item instead:
if (requestedItem.get(current.request_item)) {
// Update the Requested Item's assigned_to with the Catalog Task's assigned_to
requestedItem.assigned_to = current.assigned_to;
requestedItem.update();
Note that you aren't doing anything to update the assignment_group or distinguishing which changed. Your second GlideRecord looks OK, but if the REQ is not updating, maybe 'request' is a reserved/key word so you should change this var name, or there is another Business Rule also affecting the assigned_to, or the opening if statement is precluding anything from running. You can add some gs.info lines to log what's going on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 11:35 AM
Since you have the filter conditions, there's no need to repeat the same with your script wrapped in an if statement, but it's not really hurting anything. Since this rule is running on the sc_task table, 'current' refers to the sc_task record that was just updated. The cat_item field references the Catalog Item that the RITM is associated with, so you'll want to use request_item instead:
if (requestedItem.get(current.request_item)) {
// Update the Requested Item's assigned_to with the Catalog Task's assigned_to
requestedItem.assigned_to = current.assigned_to;
requestedItem.update();
Note that you aren't doing anything to update the assignment_group or distinguishing which changed. Your second GlideRecord looks OK, but if the REQ is not updating, maybe 'request' is a reserved/key word so you should change this var name, or there is another Business Rule also affecting the assigned_to, or the opening if statement is precluding anything from running. You can add some gs.info lines to log what's going on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 02:19 PM
This was my issue. Thanks so much for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 05:25 AM
You are welcome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 01:47 PM
I used this and got the assigned to to change, but the assigned group did not. Is that missing from the code?