Idea should not autoclose

Amit_H
Tera Contributor

Currently idea is getting close on closer of demand.

it should not get auto close when demand close if it has the open epic associated.

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @Amit_H ,

 

This is oob functionality and controlled through one BR: Update Idea State on Close.

You need to adjust the code in this BR. add below code.

(function executeRule(current, previous /*null when async*/) {

    // Check if there is an associated Demand
    var demandGr = new GlideRecord('dmn_demand');
    demandGr.addQuery('idea', current.sys_id);
    demandGr.addQuery('state', '9'); 
    demandGr.query();

    while (demandGr.next()) {
        // Check for open Epics related to the Demand
        var epicGr = new GlideRecord('rm_epic');
        epicGr.addQuery('demand', demandGr.sys_id); // Ensure 'demand' references the associated Demand
        epicGr.addEncodedQuery('stateNOT IN3,4,6); // Look for open Epics
        epicGr.query();

        if (epicGr.hasNext()) {
            gs.addErrorMessage('The Idea cannot be closed as it has associated Demands with open Epics.');
            current.setAbortAction(true); // Prevent the Idea from being closed
            break;
        }else{
var idea = new GlideRecord("idea");
	idea.get(current.idea);
	idea.setValue('close_notes', gs.getMessage("Closing idea as the corresponding demand is closed"));
	idea.setValue("state", 3);
	idea.update();

}
    }

})(current, previous);

 

 

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

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

2 REPLIES 2

Runjay Patel
Giga Sage

Hi @Amit_H ,

 

This is oob functionality and controlled through one BR: Update Idea State on Close.

You need to adjust the code in this BR. add below code.

(function executeRule(current, previous /*null when async*/) {

    // Check if there is an associated Demand
    var demandGr = new GlideRecord('dmn_demand');
    demandGr.addQuery('idea', current.sys_id);
    demandGr.addQuery('state', '9'); 
    demandGr.query();

    while (demandGr.next()) {
        // Check for open Epics related to the Demand
        var epicGr = new GlideRecord('rm_epic');
        epicGr.addQuery('demand', demandGr.sys_id); // Ensure 'demand' references the associated Demand
        epicGr.addEncodedQuery('stateNOT IN3,4,6); // Look for open Epics
        epicGr.query();

        if (epicGr.hasNext()) {
            gs.addErrorMessage('The Idea cannot be closed as it has associated Demands with open Epics.');
            current.setAbortAction(true); // Prevent the Idea from being closed
            break;
        }else{
var idea = new GlideRecord("idea");
	idea.get(current.idea);
	idea.setValue('close_notes', gs.getMessage("Closing idea as the corresponding demand is closed"));
	idea.setValue("state", 3);
	idea.update();

}
    }

})(current, previous);

 

 

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

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

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

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Amit_H 

did you check any OOB BR is doing that?

if it's some OOB BR then you can simply deactivate that.

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