how to close the child incidents by using background script?

JMR2
Mega Expert

HI All,

I have a requirement,  

I have already closed a few parent incidents, but I want child incidents to be closed automatically by using background scripts.

Any suggestions?

Thanks,

JMR

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello JMR,

Check out following script:

var gr= new GlideRecord("incident");

gr.addQuery('parent',"sysID of Incident");

gr.query();

while(gr.next()){

// here you can set values that you want to set before closing incidents

gr.setValue('state', '6'); // value for closed or resolved

gr.setWorkflow(false);

gr.autoSysFields(false)

gr.update();

}

NOTE:

1.‘setWorkflow’ is used to enable/disable the running of any business rules that may be triggered by a particular update.

2. ‘autoSysFields’ is used to disable the update of ‘sys’ fields (Updated, Created, etc.) for a particular update. This really is only used in special situations. The primary example is when you need to perform a mass update of records to true up some of the data but want to retain the original update timestamps, etc.

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

View solution in original post

4 REPLIES 4

Apeksha Joshi
Kilo Guru

HI ,

please refer this link:

https://community.servicenow.com/community?id=community_question&sys_id=52aebe65db58dbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=0d9625b6db9e97c00e3dfb651f96...

https://community.servicenow.com/community?id=community_question&sys_id=d1ffffa8dbc2bb4014d6fb243996...

it might help you .

If my reply helps you at all, I’d really appreciate it if you click the Helpful button and if my reply is the answer you were looking for, it would be awesome if you could click both the Helpful and Accepted Solution buttons!

 

Regards,

Apeksha

AbhishekGardade
Giga Sage

Hello JMR,

Check out following script:

var gr= new GlideRecord("incident");

gr.addQuery('parent',"sysID of Incident");

gr.query();

while(gr.next()){

// here you can set values that you want to set before closing incidents

gr.setValue('state', '6'); // value for closed or resolved

gr.setWorkflow(false);

gr.autoSysFields(false)

gr.update();

}

NOTE:

1.‘setWorkflow’ is used to enable/disable the running of any business rules that may be triggered by a particular update.

2. ‘autoSysFields’ is used to disable the update of ‘sys’ fields (Updated, Created, etc.) for a particular update. This really is only used in special situations. The primary example is when you need to perform a mass update of records to true up some of the data but want to retain the original update timestamps, etc.

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

Any updates on this?

Can you please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

Hi abhishek,

Thanks for your reply