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 12:43 AM
Hi @Mark Wood,
You can try this updated scripts -
var cr = new GlideRecord('change_request');
cr.addQuery('parent', current.getUniqueValue());
cr.query();
while (cr.next()) {
if (cr.state == 3) // if state is closed
{
gs.addInfoMessage("You can Close Problem");
} else {
gs.addErrorMessage("Associated Change is not resolved, Please resolve change to proceed with problem resolution");
current.state = 104;
current.update();
current.setAbortAction(true);
}
}
Feel free to mark helpful and correct! 👍🏻
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 12:49 AM
Hello @Sagar Pagar,
I've tried the code you provided, but it's not functioning as expected. It's changing the state of the problem to "resolved," which shouldn't happen. Please find the attached screenshot for your reference.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 01:13 AM
Hi @Mark Wood,
My mistake - we do not needed current.update and state line here. this is updated scripts -
var cr = new GlideRecord('change_request');
cr.addQuery('parent', current.getUniqueValue());
cr.query();
while (cr.next()) {
if (cr.state == 3) // if state is closed
{
gs.addInfoMessage("You can Close Problem");
} else {
gs.addErrorMessage("Associated Change is not resolved, Please resolve change to proceed with problem resolution");
current.setAbortAction(true);
}
}
Feel free to mark helpful and correct! 👍🏻
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 01:00 AM
@Mark Wood : If I understood your ask correctly, basically you don't want to close the problem until it's related changes is closed.
To achieve this , no script is required. There is OOB change request field on problem table. Provided that field should be linked to related change request. If yes then follow below steps.
1. Create Business rule on Problem table (before update)
2. When to run condition- Problem state changes to closed and by dot walking get change request state field (show related fields) is not closed.
3. then in actions table select "abort action".
Hope it helps. Kindly mark helpful/accepted if it helps.
Regards,
Priyanka Salunke