Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Backgorund script

SANNAPUREDDYV
Tera Contributor

what is the background script for print the active incidents associated to the closed problem and close those incidents?

1 ACCEPTED SOLUTION

Sid_Takali
Kilo Patron

Hi @SANNAPUREDDYV Try below code and modify accordingly 

var problemGR = new GlideRecord('problem');

problemGR.addQuery('state', '6'); 
problemGR.query();

while (problemGR.next()) {
    var incidentGR = new GlideRecord('incident');
    
    incidentGR.addQuery('problem', problemGR.sys_id);
    incidentGR.addQuery('state', '!=', '7'); 
    incidentGR.query();
    
    while (incidentGR.next()) {
        gs.info('Closing Incident: ' + incidentGR.number + ' associated with Problem: ' + problemGR.number);
        
        // Close the incident
        incidentGR.state = '7'; 
        incidentGR.update();
    }
}

gs.info('Script completed successfully.');

  

View solution in original post

1 REPLY 1

Sid_Takali
Kilo Patron

Hi @SANNAPUREDDYV Try below code and modify accordingly 

var problemGR = new GlideRecord('problem');

problemGR.addQuery('state', '6'); 
problemGR.query();

while (problemGR.next()) {
    var incidentGR = new GlideRecord('incident');
    
    incidentGR.addQuery('problem', problemGR.sys_id);
    incidentGR.addQuery('state', '!=', '7'); 
    incidentGR.query();
    
    while (incidentGR.next()) {
        gs.info('Closing Incident: ' + incidentGR.number + ' associated with Problem: ' + problemGR.number);
        
        // Close the incident
        incidentGR.state = '7'; 
        incidentGR.update();
    }
}

gs.info('Script completed successfully.');