Updating Assignment on the RITM and REQ when it is changed on the CTASK

DTrishman
Tera Contributor

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:

DTrishman_0-1698253086428.png

DTrishman_1-1698253112891.png

 

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

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.

 

View solution in original post

5 REPLIES 5

Yes, this was not included in the solution as I was working off of the author's initial attempt.  If you want to do update the Assignment group from the task you could just add a line before the update:

requestedItem.assignment_group = current.assignment_group;

but this would just update both anytime either changed, so if you want to be more selective, split the rule into two or split the script into two sections - if assignment group changes update assignment group, if assigned to changes update assigned to...