Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 12:39 AM
Hello Experts,
I'm currently working on the following requirements:
"When a change record is created for implementing a problem resolution, the problem ticket cannot be closed until the change is in a Closed-Complete state."
To achieve this requirement, I've written a before-update business rule with the condition that the state changes to resolved. However, it seems that my code is not functioning as expected. Could anyone please provide guidance on this?
Thank you.
(function executeRule(current, previous /*null when async*/) {
var cr=new GlideRecord('change_request');
cr.addQuery('parent',current.sys_id);
cr.query();
while(cr.next())
{
if(cr.state!=3)//not closed
{
gs.addErrorMessage("Associated Change is not resolved, Please resolve change to proceed with problem resolution");
current.state=104;
current.update();
current.setAbortAction(true);
}
else{
gs.addInfoMessage("You can Close Problem");
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 01:02 AM
Hi @Mark Wood how are you associating the change? Are you creating change request from Problem via UI Action? How are you linking the change request to Problem? Which field holds the relationship?
your BR will look like this on problem table
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 01:03 AM
Hi @Mark Wood
You can try below script,
Hope you are using Before Update BR on the problem table.
var cr=new GlideRecord('change_request');
cr.addQuery('parent',current.sys_id);
cr.addQuery("state", "!=", "3");
cr.query();
if(cr.next()){
current.setAbortAction(true);
gs.addErrorMessage("Associated Change is not resolved, Please resolve change to proceed with problem resolution");
}
else{
gs.addInfoMessage("You can Close Problem");
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 01:20 AM - edited 02-29-2024 01:21 AM
Hello @Mark Wood
Create an Before Update Business rule on Problem table and try using below script: add when to run condition as State is Closed
(function executeRule(current, previous /*previous is not used in this example*/) {
if (current.getTableName() === 'problem') {
var changeGR = new GlideRecord('change_request');
changeGR.addQuery('parent', current.sys_id); // Assuming 'problem_id' is the reference field to problem table in change_request table
changeGR.query();
var allChangesClosedComplete = true;
while (changeGR.next()) {
if (changeGR.state != 3 /*assuming 3 is the Closed-Complete state*/) {
// Set the flag to false and break out of the loop
allChangesClosedComplete = false;
break;
}
}
// Check if all associated change requests are in "Closed-Complete" state
if (allChangesClosedComplete) {
// Allow closing the problem ticket
return;
} else {
// Prevent closing the problem ticket and display an error message
current.setAbortAction(true);
gs.addErrorMessage('Cannot close the problem ticket until all associated changes are in a "Closed-Complete" state.');
return;
}
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Pratiksha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 04:33 AM
Hello @Mark Wood -
I noticed that you marked my answer as helpful.
So if resolves your query then please Accept my solution ✔️ as well and close the thread to help future readers to understand.
Thank You!