- 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 04:19 AM
@VIKAS MISHRA can you share your script once please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 04:22 AM
I am using below mentioned script
var incArray = ["INC0014705", "INC0014697"];
gs.info(incArray + " - " + incArray.length);
for (var i = 0; i < incArray.length; i++) {
var gr = new GlideRecord('incident');
gr.query("number", incArray[i]);
gr.query();
if (gr.next()) {
gr.state.close_code = 'Solved (Permanently)';
gr.state.close_notes = "Resolving the incident";
gr.state = 6;
gr.setWorkflow(false);
gr.update();
}
}
- 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 04:22 AM
I am Using below mentioned script:
var incArray = ["INC0014705", "INC0014697"];
gs.info(incArray + " - " + incArray.length);
for (var i = 0; i < incArray.length; i++) {
var gr = new GlideRecord('incident');
gr.query("number", incArray[i]);
gr.query();
if (gr.next()) {
gr.state.close_code = 'Solved (Permanently)';
gr.state.close_notes = "Resolving the incident";
gr.state = 6;
gr.setWorkflow(false);
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2022 04:26 AM
Its working now, thank you
Actully i was using wrong backend name of those 2 fields