State update between RITM and Task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:15 AM
Hi All,
I have a requirement when the catalog task state should be updated with the RITM state. Below is the scenario.
One RITM has two parallel tasks. One task is pending customer action and another one is a work in progress.
I need to update the RITM state to Pending for customer action if any of them is in pending customer action.
How to achieve this requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:24 AM
Hi @Sanjeeva Nagend ,
You can create a Business Rule on the Catalog Task table to update the RITM state whenever the catalog task state is updated.
Here are the steps to create the Business Rule:
- Navigate to "Business Rules" in the left navigation pane.
- Click on "New" to create a new Business Rule.
- Set the "Table" field to "Catalog Task".
- Set the "When to run" field to "Before".
- Set the "Advanced" field to "true".
- In the "Advanced" field, enter the following script:
if (current.sys_class_name == "sc_task" && current.request_item != null) {
var ritm = new GlideRecord("sc_request");
if (ritm.get(current.request_item)) {
var pendingTasks = new GlideAggregate("sc_task");
pendingTasks.addQuery("request_item", ritm.sys_id);
pendingTasks.addQuery("state", "IN", "pending");
pendingTasks.addAggregate("COUNT");
pendingTasks.query();
if (pendingTasks.next() && pendingTasks.getAggregate("COUNT") > 0) {
ritm.setValue("state", 3); // Update RITM state to "Pending for customer action"
ritm.update();
}
}
}
This script checks if the current record is a Catalog Task record and if it has an associated RITM. Then it checks if there are any pending tasks for that RITM. If there are, it updates the RITM state to "Pending for customer action".
7. Give the Business Rule a name and save it.
Once the Business Rule is active, it will automatically update the RITM state whenever a Catalog Task state is updated to "pending".
If my response helps you to resolve the issue close the question by ✅Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.
Thanks,
Ratnakar