Closure of change request with inactive/no change task

Annirnita Dash1
Tera Contributor

Hi All,

I have a request where I have to add few filters and mark change request as closed.

Conditions are:

 

All those change request which are not updated from 10 days.

there are no active change task under it, or they have no change task at all.

All such change where multiple ctasks are there with some active and some inactive shall be ignored. Only those with all inactive ones will be considered.

 

I tried gliding to ctask, checking with all filters , but confused with how to check for changes without a change task.

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @Annirnita Dash1 ,

 

You can create a schedule job and set run as daily.

 

Use below script to close the change based on your condition.

var gr = new GlideRecord('change_request');
gr.addEncodedQuery('sys_updated_onRELATIVELT@dayofweek@ago@10');
gr.query();
while (gr.next()) {

    var gr2 = new GlideRecord('change_task');
    gr2.addEncodedQuery('change_request=' + gr.sys_id + '^active=true');
    gr2.query();
    if (!gr2.next()) {

        gr.state = 3;
        gs.setWokflow(false);
        gr.update();
    }


}

 

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

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

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Annirnita Dash1 

 

I have no idea how this can be done, but you can create a report for same upto some extent as per my experience

 

AGLearnNGrow_0-1730709245368.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

@Dr Atul G- LNG , thanks for the reply.

I have to mark this change as closed, so report will only give me data.

Hi @Annirnita Dash1 

 

Yes correct, report will give only data. Might be use that data in flow to close teh changes.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Runjay Patel
Giga Sage

Hi @Annirnita Dash1 ,

 

You can create a schedule job and set run as daily.

 

Use below script to close the change based on your condition.

var gr = new GlideRecord('change_request');
gr.addEncodedQuery('sys_updated_onRELATIVELT@dayofweek@ago@10');
gr.query();
while (gr.next()) {

    var gr2 = new GlideRecord('change_task');
    gr2.addEncodedQuery('change_request=' + gr.sys_id + '^active=true');
    gr2.query();
    if (!gr2.next()) {

        gr.state = 3;
        gs.setWokflow(false);
        gr.update();
    }


}

 

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

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

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