story should not close if associated defect is open

Prakash_S
Tera Contributor

I have a requirement to prevent story closer if defect is still active.

I tried with writing BR but not working.

(function executeRule(current, previous /*null when async*/) {
    // Query the defect table for associated defects
    var defectGr = new GlideRecord('rm_defect'); // Replace 'rm_defect' with the actual defect table name
    defectGr.addQuery('story', current.sys_id); // Assuming 'story' is the reference field on the defect table
    defectGr.addQuery('state', '!=', 'Closed'); // Replace 'state' and 'Closed' with actual field and value
    defectGr.query();

    if (defectGr.hasNext()) {
        // Prevent the story from being closed
        gs.addErrorMessage('This story cannot be closed because it has associated defects that are still open.');
        current.state = previous.state; // Revert the state change
        gs.log('Story closure prevented due to open defects: ' + current.number, 'Story Closure Rule');
    }
})(current, previous);

  

2 ACCEPTED SOLUTIONS

Runjay Patel
Giga Sage

Hi @Prakash_S ,

 

You can achieve it via configuration of BR.

RunjayPatel_0-1734678768483.png

 

RunjayPatel_1-1734678859845.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

 

View solution in original post

Hemanth M1
Giga Sage
Giga Sage

Hi @Prakash_S ,

 

Why don't use defect field on the story to check if still active and abort action. 

 

You don't need to any scripting logic

Step 1)

HemanthM1_2-1734679225441.png

 

step 2)

HemanthM1_1-1734679076544.png

 

Hope this helps!!!

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

5 REPLIES 5

Hemanth M1
Giga Sage
Giga Sage

Hi @Prakash_S ,

 

Why don't use defect field on the story to check if still active and abort action. 

 

You don't need to any scripting logic

Step 1)

HemanthM1_2-1734679225441.png

 

step 2)

HemanthM1_1-1734679076544.png

 

Hope this helps!!!

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025