Service Now update()

4.2k views Asked by At

I want update problem state as closed when incident state is closed

I tried this code but it is updating all the records in problem table, But I want to update only that related table.

// update the state of all active incidents to 4 - "Awaiting User Info"
var gr = new GlideRecord('incident')
gr.addQuery('active', true);
gr.query();
gr.state = 4;
gr.updateMultiple();
1

There are 1 answers

0
Tim Woodruff On

It sounds like you could use a little glide scripting help. Try something more like this:

// update the state of all active incidents to 4 - "Awaiting User Info"
var gr = new GlideRecord('incident'); //Create the glide record
gr.addQuery('sys_id', current.incident_ref_field); //Only the relevant record should be returned.
gr.query();
if (gr.next()) {
    gr.state = 4;
    gr.update();
}

You only want the one related inc record, so we make sure that the returned record matches the record in the ref field (which I've called incident_ref_field, but you should change to the actual field name).