- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 02:51 AM
I have 10 incidents where i need to change the state of all the incidents from open to close.
i do not have any condition/filter to put in the Glide record to get all these 10 records hence i want to create one array where i will mentioned all the 10 incidents then will run a loop so that it will close all the incidents one after another,
Please suggest the background script for this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 03:02 AM
Hi @VIKAS MISHRA,
Here is sample scripts. modify it accordingly.
var incArray = ["INC12345", "INC23456", "INC4353464", "INC5676578"];
gs.info(incArray + " - " + incArray.length);
for (var i = 0; i < incArray.length; i++) {
var inc_record = new GlideRecord('incident');
inc_record.query("number", incArray[i]);
inc_record.query();
if (inc_record.next()) {
inc_record.field_name1 = "values1";
inc_record.field_name2 = "values2";
inc_record.setWorkflow(false);
inc_record.autoSysFields(false);
inc_record.update()
}
}
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 03:13 AM - edited ‎11-07-2022 03:14 AM
hello @VIKAS MISHRA ,
you can try this script
var incs = ["incident number 1", "incident number 2", "incident number 3", "incident number 4"];
// store your 10 incident numbers in this array
for (var i = 0; i < incs.length; i++) {
var gr = new GlideRecord('incident');
gr.addQuery("number",incs[i]);
gr.query();
if (gr.next()) {
gr.state= "state_choice_value";
gr.update();
}
}
Hope this helps
Mark the answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 04:19 AM
Show your script
If should be something like below
var incs = ["incident number 1", "incident number 2", "incident number 3", "incident number 4"];
// store your 10 incident numbers in this array
for (var i = 0; i < incs.length; i++) {
var gr = new GlideRecord('incident');
gr.addQuery("number",incs[i]);
gr.query();
if (gr.next()) {
gr.state= "<Add yiour resolved state value>"; //You need to add this valye in <> from your instance
gr.<close_code> = '<Close Code in yoiur instance>'; //You need to add this valye in <> from your instance
gr.<close_notes> = '<text value you want to add as notes>'; //You need to add this valye in <> from your instance
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 03:02 AM
Hi @VIKAS MISHRA,
Here is sample scripts. modify it accordingly.
var incArray = ["INC12345", "INC23456", "INC4353464", "INC5676578"];
gs.info(incArray + " - " + incArray.length);
for (var i = 0; i < incArray.length; i++) {
var inc_record = new GlideRecord('incident');
inc_record.query("number", incArray[i]);
inc_record.query();
if (inc_record.next()) {
inc_record.field_name1 = "values1";
inc_record.field_name2 = "values2";
inc_record.setWorkflow(false);
inc_record.autoSysFields(false);
inc_record.update()
}
}
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 03:58 AM
Thanks for the above mentioned script, but when i am using this script then field "resolution code" and resolved Note" are coming as mandatory hence incident is not getting updated.
I tried to jupdat those 2 fields along with the state field but still getting below mentioned error :
*** Script: INC0014697,INC0014705 - 2
Background message, type:error, message: Data Policy Exception: The following fields are mandatory: Resolution code, Close notes
Background message, type:error, message: Data Policy Exception: The following fields are mandatory: Resolution code, Close notes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 03:13 AM - edited ‎11-07-2022 03:14 AM
hello @VIKAS MISHRA ,
you can try this script
var incs = ["incident number 1", "incident number 2", "incident number 3", "incident number 4"];
// store your 10 incident numbers in this array
for (var i = 0; i < incs.length; i++) {
var gr = new GlideRecord('incident');
gr.addQuery("number",incs[i]);
gr.query();
if (gr.next()) {
gr.state= "state_choice_value";
gr.update();
}
}
Hope this helps
Mark the answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 04:06 AM
Thanks for the above mentioned script, but when i am using this script then field "resolution code" and resolved Note" are coming as mandatory hence incident is not getting updated.
I tried to jupdat those 2 fields along with the state field but still getting below mentioned error :
*** Script: INC0014697,INC0014705 - 2
Background message, type:error, message: Data Policy Exception: The following fields are mandatory: Resolution code, Close notes
Background message, type:error, message: Data Policy Exception: The following fields are mandatory: Resolution code, Close notes