- 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 11:04 PM
Hi @Danish Bhairag2 , No luck. Please review & suggest
if (current.state == '3' && previous.state != '3') {
var gr = new GlideRecord('change_request');
gr.addQuery('u_demand_task', current.sys_id); // u_demand_task is the field on CHG which hold Demand Task number
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.');
}
}
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 02:32 AM
This worked for me.
(function executeRule(current, previous /*null when async*/ ) {
if (current.state == '3' && previous.state != '3') {
var gr = new GlideRecord('change_request');
gr.addQuery('u_demand_task', current.sys_id); // u_demand_task = Field on CHG
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);