Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

paddy786
Tera Contributor

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

2 REPLIES 2

Harsh Vardhan
Giga Patron

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

 

 

Nitesh Balusu
Giga Guru

  gr.setWorkflow(false);

 

This statement wouldn't be required, any reason you're using a background script to get this done?