- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-27-2025 10:15 PM
Hi
can anyone help me with the code correction for scenario when:
Parent ritm has been cancelled through request table through ui action button named as ' cancel' or the parent ritm approvers has been rejected in sc_req_item table
i want to cancel a child related ritm in the field called as 'sgdc_ref' (backend value)
i have written a ' after' business rule with an insert and update and condition as approvers has been rejected, how to add a condition for the ui action button as cancel in sc_req table
below code :
(function executeRule(current, previous /*null when async*/)
{ if (current.state == 4)
var childRITMs = new GlideRecord('sc_req_item');
childRITMs.addQuery('sgdc_ref', current.request);
childRITMs.query();
while (childRITMs.next()) {
if (childRITMs.state != 4)
childRITMs.state = 4;
childRITMs.update();
})(current, previous);
request to please help me with code correction
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-27-2025 10:30 PM
@raj765_32 You can try with the below updated code:
(function executeRule(current, previous /*null when async*/) {
if (current.state == 4) {
if (current.canceled_via_ui_action == true || previous.state != current.state) {
var childRITMs = new GlideRecord('sc_req_item');
childRITMs.addQuery('sgdc_ref', current.request);
childRITMs.query();
while (childRITMs.next()) {
if (childRITMs.state != 4) {
childRITMs.state = 4;
childRITMs.update();
}
}
}
}
if (current.state == 3) {
var childRITMs = new GlideRecord('sc_req_item');
childRITMs.addQuery('sgdc_ref', current.request);
childRITMs.query();
while (childRITMs.next()) {
if (childRITMs.state != 4) {
childRITMs.state = 4;
childRITMs.update();
}
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-27-2025 10:29 PM
Hi @raj765_32 ,
Please refer below code.
(function executeRule(current, previous /*null when async*/ ) {
if (current.state == 4 && previous.state != 4) {
// Get all child RITMs related to this parent
var childRITMs = new GlideRecord('sc_req_item');
childRITMs.addQuery('parent', current.sys_id);
childRITMs.addQuery('state', '!=', 4); // Only update non-cancelled RITMs
childRITMs.query();
while (childRITMs.next()) {
childRITMs.state = 4; // Set state to "Cancelled"
childRITMs.update();
}
}
})(current, previous);
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-27-2025 10:37 PM
hi divesh,
the cancel ui button is in sc_req table and here you are writing code in sc_req_item table?
and there is another scenario when the parent ritm approver has been rejected also child related ritm need to be closed incomplete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-27-2025 10:30 PM
@raj765_32 You can try with the below updated code:
(function executeRule(current, previous /*null when async*/) {
if (current.state == 4) {
if (current.canceled_via_ui_action == true || previous.state != current.state) {
var childRITMs = new GlideRecord('sc_req_item');
childRITMs.addQuery('sgdc_ref', current.request);
childRITMs.query();
while (childRITMs.next()) {
if (childRITMs.state != 4) {
childRITMs.state = 4;
childRITMs.update();
}
}
}
}
if (current.state == 3) {
var childRITMs = new GlideRecord('sc_req_item');
childRITMs.addQuery('sgdc_ref', current.request);
childRITMs.query();
while (childRITMs.next()) {
if (childRITMs.state != 4) {
childRITMs.state = 4;
childRITMs.update();
}
}
}
})(current, previous);