- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2019 03:32 AM
Hello, I have an array that has a bunch of sys ids of my query. Let’s us say that my array has a list of open incidents/ incident task and is defined as follow
var allIncidents = [];
assuming that my records are are in it already , how can I change the attribute for all records (sys_id) for example to open , open = 4
i am doing this:
allIncidents.state = 4;
but it it seems to not work
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2019 03:39 AM
You will need to use those sys_ids to access the incident table, find the records and then update them. here are some options:
//iterate throught the array and update each record individually:
var allIncidents = [];
var gr = new GlideRecord('incident');
for(var i=0; i< allIncidents.length; i++){
if(gr.get(allIncidents[i]){
gr.state = 4;
gr.update();
}
}
//get all records in a glide query and use update multiple:
var allIncidents = [];
var gr = new GlideRecord('incident');
gr.addEncodedQuery('sys_idIN' + allIncidents);
gr.query();
gr.setValue('state', 4);
gr.updateMultiple();
EDIT: incident and incident_task are different tables so you won't be able to update all records in an array that contains sys_id's for each table. Create 2 arrays, one with incidents and the other with incident_tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2019 03:39 AM
You will need to use those sys_ids to access the incident table, find the records and then update them. here are some options:
//iterate throught the array and update each record individually:
var allIncidents = [];
var gr = new GlideRecord('incident');
for(var i=0; i< allIncidents.length; i++){
if(gr.get(allIncidents[i]){
gr.state = 4;
gr.update();
}
}
//get all records in a glide query and use update multiple:
var allIncidents = [];
var gr = new GlideRecord('incident');
gr.addEncodedQuery('sys_idIN' + allIncidents);
gr.query();
gr.setValue('state', 4);
gr.updateMultiple();
EDIT: incident and incident_task are different tables so you won't be able to update all records in an array that contains sys_id's for each table. Create 2 arrays, one with incidents and the other with incident_tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2019 12:16 AM
Hi Leandre,
Did this answer your question? If your issue is resolved please mark my answer correct.
Cheers
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2019 06:49 AM
thank you David !