How to update SCTASK worknotes when worknotes is added to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 05:01 AM
I have written a business rule on sc_req_item i.e after insert here is the code
In this i am not getting record by doing grp.getRowCount() in system log i am getting 0.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 05:31 AM
hi @sanasayyad
Instead of running the business rule on insert, configure it to run on update when the work_notes field changes. This ensures that sc_task records are more likely to exist, as they are typically created shortly after the RITM is inserted.
When a Requested Item (RITM) is created, the associated catalog tasks (sc_task) are usually generated by a workflow or script that runs after the RITM is inserted. At the moment your business rule executes (after insert on sc_req_item), the sc_task records may not yet exist in the database.
update your code as bellow and try once:
// Check if work_notes has been updated
if (current.work_notes.changes()) {
// Log the work notes update for debugging
gs.info("Work notes updated on RITM: " + current.number + ", New work notes: " + current.work_notes);
// Query related sc_task records
var grp = new GlideRecord('sc_task');
grp.addQuery('request_item', current.sys_id);
grp.query();
gs.info("Found " + grp.getRowCount() + " sc_task records for RITM: " + current.number);
// Loop through all related tasks and update work_notes
while (grp.next()) {
grp.work_notes = current.work_notes; // Copy the RITM work notes to the task
grp.setWorkflow(false); // Prevent triggering other business rules/workflows
grp.update();
gs.info("Updated work_notes for sc_task: " + grp.number);
}
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 05:39 AM
@sanasayyad If your goal is to update work notes for every task created under a RITM, just move the logic to the sc_task table itself, When: After Insert, Condition: request_item != ''
script:
(function executeRule(current, previous /*null when async*/ ) {
current.work_notes = "test from task";
current.update();
})(current, previous);