How can I simply update the state of an incident with a background script?

Kenisha Morgan1
Kilo Expert

Hey Everyone, 

 

I need to simply update the State of 1 incident record to Closed. 

 

What is wrong with my code? 

var incidentGR = GlideRecord('incident');
incidentGR.get('sys_id');
incidentGR.state.setValue('Closed');
incidentGR.update();

 

What am I doing wrong? It runs, but it isn't updating that specific incident. 

 

Thanks,

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

var incidentGR = GlideRecord('incident');
incidentGR.get('sys_id'); //you need to place actual sys_id of the record here
incidentGR.setValue('state', 7); //whatever the back-end value for Closed is, OOB is 7
incidentGR.update();

find_real_file.png

For future reference, please refer to GlideRecord documentation for appropriate formatting, etc.: https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/c_GlideRecordScope...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

1 REPLY 1

Allen Andreas
Administrator
Administrator

Hi,

var incidentGR = GlideRecord('incident');
incidentGR.get('sys_id'); //you need to place actual sys_id of the record here
incidentGR.setValue('state', 7); //whatever the back-end value for Closed is, OOB is 7
incidentGR.update();

find_real_file.png

For future reference, please refer to GlideRecord documentation for appropriate formatting, etc.: https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/c_GlideRecordScope...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!