Business rule getting triggered even when conditions are not matching

sath
Tera Expert

Hi,

 

I have created a UI action ''Create Defect' on stories. When a defect created from story is closed complete, story state should be moved to ready for testing, I have created a update and after business rule on defect to move the story to ready for testing.

(function executeRule(current, previous /*null when async*/ ) {
    var story = new GlideRecord('rm_story');
    story.addQuery('sys_id', current.reported_against);
    story.query();
    if (story.next()) {
        if (current.state == '3') {
            story.state = '-7';
           
        } else if (current.state == '7') {
            story.state = '-7';
            
        }
        story.update();
    }
})(current, previous);

This business rule is working fine except it's creating below error message even when I move the defect to closed complete. And I'm not changing any product or project field on story.

Screenshot 2025-03-07 at 8.47.18 AM.png

Please assist.

1 ACCEPTED SOLUTION

Shivalika
Mega Sage

Hello Sath, 

 

It's happening because the product value that you checking is null in the story. 

 

Instead modify the condition to check if the product value exists and then check with or conditions, something like below. 

 

current.product && current.product.changes -

 

this first checks if the product exists and then checks if product's value is changed. This shouldn't give any null checks as well. You can further modify it to add more conditions per requirement.

 

Please mark my answer as helpful if it helped your query in anyway. 

View solution in original post

19 REPLIES 19

@sath  could you please tell the values of product and project on the story, are they null?


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Product value is populated and I don't even see project field on story table. This is OOB BR

Ankur Bawiskar
Tera Patron
Tera Patron

@sath 

did you check the update is causing some other update business rule to run which is causing the BR in your screenshot to trigger?

Did you debug business rules and see?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar , I don't see any logic that triggering this BR "Set Product Backlog Type" and don't see much info on debug business rule as well.

Vishal Jaswal
Giga Sage

Hello @sath 

 

try below

 

(function executeRule(current, previous /*null when async*/) {
var story = new GlideRecord('rm_story');
story.addQuery('sys_id', current.reported_against);
story.query();

if (story.next()) {
if (current.state == '3' || current.state == '7') {
story.state = '-7';
story.setWorkflow(false); // Prevents triggering other rules/workflows
story.update();
story.setWorkflow(true); // Restores normal workflow execution
}
}
})(current, previous);

 


Hope that helps!