How to CLOSE a Problem Record/Ticket using Background script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2018 09:42 AM
I have used the below script, but the PROBLEM ticket is going to PENDING status & not to CLOSED status as i wanted.
var gr = new GlideRecord('problem');
gr.addQuery('number','PRB000011568');
gr.query();
while(gr.next())
{
gr.setWorkflow(false);
gr.problem_state= 4; //to close;
gr.u_substatus= 'Cancelled';
//gs.print();
gr.update();
}
Can any body help me in this matter.
any help would be greatly appreciated.
- Paddy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2018 11:21 AM
var gr = new GlideRecord('problem');
gr.addQuery('number','PRB000011568');
gr.query();
if(gr.next())
{
gr.state= 4; //to close;
gr.u_substatus= 'Cancelled';
gr.update();
}
OR
var gr = new GlideRecord('problem');
gr.addQuery('sys_id','<sys id or the record>');
gr.query();
if(gr.next())
{
gr.state= 4; // problem field state.
gr.u_substatus= 'Cancelled';
gr.update();
}
Note: you can try with any of the above script..
adding link below for more details about the background script functionality. in which scenario you should use it with an example kindly refer that also.
https://www.servicenowelite.com/blog/2017/8/25/code-vault/background-scripts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2018 08:30 PM
gr.setWorkflow(false);
This statement wouldn't be required, any reason you're using a background script to get this done?