- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 02:23 AM
Hello Developers,
We have an UI action 'create change' on Demand task table.
Each Demand task will have an CHG attached to it.
Before closing the Demand Task, The attached CHG must be closed.
I have wrote a below BR but does not seem working.
Can you please suggest something?
3 is closed for both CHG & Demand task
(function executeRule(current, previous /*null when async*/) {
if (current.state == '3' && previous.state != '3') {
var gr = new GlideRecord('change_request'); // Replace with the related table name
gr.addQuery('u_demand_task', current.sys_id); // Assuming 'demand_task' is the reference field
gr.addQuery('state', '!=', '3');
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage('Cannot close this Demand Task until related Changes are closed.');
gs.info('Demand Task: ' + current.sys_id + ' has open related changes.');
current.setAbortAction(true);
} else {
gs.info('Demand Task: ' + current.sys_id + ' can be closed as all related changes are closed.');
}
}
})(current, previous);
I get the error even when CHG is closed.
Please suggest what went wrong here.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 02:33 AM
Hi @Naveen87 ,
You can add the filter condition in the BR when to run section as state changes to closed. Then u can try below code
var gr = new GlideRecord('change_request'); // Replace with the related table name
gr.addQuery('u_demand_task', current.sys_id); // Assuming 'demand_task' is the reference field
gr.addQuery('state', '!=', '3');
gr.query();
if (gr.next()) {
gs.addErrorMessage('Cannot close this Demand Task until related Changes are closed.');
gs.info('Demand Task: ' + current.sys_id + ' has open related changes.');
current.setAbortAction(true);
} else {
gs.info('Demand Task: ' + current.sys_id + ' can be closed as all related changes are closed.');
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 02:31 AM
Have you applied the filter manually to the change request table to double check nothing exists which would be causing the GlideRecord to find a change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 03:09 AM
Below line did not do anything, Hence I have changed this line
gr.addQuery('u_demand_task', current.sys_id); // Assuming 'demand_task' is the reference field
to
gr.addQuery('parent', current.sys_id); // Assuming 'demand_task' is the reference field
Parent is a field on CHG record which hold Demand value & I found that it was validating all the CHG attached to this Demand instead of Demand task. When all the CHG attached to DMD was closed. BR was working as expected.
Now the task is to show DMDTASK at Parent level & then validate.
I'm setting these values via UI action.
Now when UI action 'create change' is clicked, Demand & Parent fields are not fetching anything. Suggest me on this. I believe once we get DTASK here & BR will work as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 01:34 AM
instead of getValue('number') can you try getValue('sys_id')?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 02:33 AM
Hi @Naveen87 ,
You can add the filter condition in the BR when to run section as state changes to closed. Then u can try below code
var gr = new GlideRecord('change_request'); // Replace with the related table name
gr.addQuery('u_demand_task', current.sys_id); // Assuming 'demand_task' is the reference field
gr.addQuery('state', '!=', '3');
gr.query();
if (gr.next()) {
gs.addErrorMessage('Cannot close this Demand Task until related Changes are closed.');
gs.info('Demand Task: ' + current.sys_id + ' has open related changes.');
current.setAbortAction(true);
} else {
gs.info('Demand Task: ' + current.sys_id + ' can be closed as all related changes are closed.');
}
Thanks,
Danish