Reference incidents into change_request table

Rafael Batistot
Tera Sage

Hi Team!!

i need help to referente an incident into the change_request table

RafaelBatistot_0-1737987564608.png
In this table i possible to reference incident as below. The problem here is when the state is Closed this option "NEW" and "EDIT" not appear any more. 

RafaelBatistot_1-1737987692509.png

I'm trying to see the incidents using a simple scrip 

 

var changeRequestNumber = 'REQUEST_NUMBER';

var grChangeRequest = new GlideRecord('change_request');

if (grChangeRequest.get('number', changeRequestNumber)) {

    var gr = new GlideRecord('incident');
    gr.addQuery('change_request', grChangeRequest.sys_id);
    gr.query();
    if (gr.next()) {
        gs.info(gr.number);
    }

}

 

The situation is this part of code 

 gr.addQuery('change_request', grChangeRequest.sys_id);

it's not correct, i believe that if i find the correct reference query it's will be possible

i've tried to do this button "NEW" and "EDIT" by ACL, Client Script... But not work

Thank you in advanced


1 ACCEPTED SOLUTION

Use this as fix script or back ground script. You only need to change the first two lines with the change number (used to find the change request) and the incident number(s) (if multiple, use a comma to separate the numbers).

 

var grChangeNr = 'CHG1237467';
var grIncNrs = 'INC123456789,INC987654321';

var grChange = new GlideRecord('change_request');
grChange.addQuery('number',grChangeNr);
grChange.query();
if(grChange.next()){
    var grInc = new GlideRecord('incident');
    grInc.addEncodedQuery('numberIN' + grIncNrs);
    grInc.query();
    while(grInc.next()){
        grInc.setValue('change_request',grChange);
        grInc.update();
    }
}

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

3 REPLIES 3

Mark Manders
Mega Patron

Once a change is closed, you can't add incidents to it anymore. Process wise it is weird to have a change executed for incident fixing and only later add the incidents to it (after the Change is already closed). Because of this, it is not possible OOB. 

What are you trying to do with the script? You already have those incidents on the related list of the Change and you can filter the Incident list on the Change request field, so see the same. What is your goal with the script? 

 

You solution is to add the change to the change request field on the incident, because it will establish the same relation.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Rafael Batistot
Tera Sage

Hi Mark, thank you for your time

I know... i'ts a not good practice but, we're having many issue from user that forget to reference those incident and i would like to, when this happened, reference those missed incidents with a script or some like that

This script that i've posted is to bring a list of request that have or not incidents, if the a request is incident missed i inserted by scrip 

Use this as fix script or back ground script. You only need to change the first two lines with the change number (used to find the change request) and the incident number(s) (if multiple, use a comma to separate the numbers).

 

var grChangeNr = 'CHG1237467';
var grIncNrs = 'INC123456789,INC987654321';

var grChange = new GlideRecord('change_request');
grChange.addQuery('number',grChangeNr);
grChange.query();
if(grChange.next()){
    var grInc = new GlideRecord('incident');
    grInc.addEncodedQuery('numberIN' + grIncNrs);
    grInc.query();
    while(grInc.next()){
        grInc.setValue('change_request',grChange);
        grInc.update();
    }
}

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark