How to check whether all the stories are closed in an EPIC?

Shantharao
Kilo Sage

Hi All,
How do you check whether all the stories are closed in an EPIC?
Can you provide me the GlideRecord scripting to check all the stories associated with EPIC were closed
before the closing of the last story? I need to complete the EPIC state based on the last story closure value of an EPCI

Thanks

1 REPLY 1

Tom Alday
Mega Guru
(function executeRule(current, previous /*null when async*/) {
    // Check if the record being updated is an Epic and the state is being changed to "Closed"
    if (current.state == 'Closed' && previous.state != 'Closed') {
        // Query all related stories
        var story = new GlideRecord('rm_story');
        story.addQuery('epic', current.getUniqueValue());
        story.addQuery('state', 'Open');
        story.query();

        // Check if any stories are still open
        if (story.hasNext()) {
            // If there are open stories, prevent changing the Epic state to "Closed"
            gs.addErrorMessage("Cannot close the Epic because there are associated open stories.");
            current.state.setDisplayValue(previous.state.getDisplayValue()); // Revert the state change
            current.setAbortAction(true);
            return;
        }
    }
})(current, previous);