Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Background script to link incident to a problem

PapaiD
Tera Contributor

Hello Everyone,

Greetings All!

I have been trying to link an incident to a problem using background script. I have used the below script but it is not quite working for me.

Can anyone help me out with this:

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0010008');
gr.addNullQuery('problem_id');
gr.query();
while(gr.next()){
        gr.problem_id = "PRB0001000";
        gr.update();
    }
 
Thanks and regards
2 ACCEPTED SOLUTIONS

Gangadhar Ravi
Giga Sage

Hi @PapaiD 

 

You need to use sys_id of the problem record since that is reference field.

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0010008');
gr.addNullQuery('problem_id');
gr.query();
while(gr.next()){
        gr.problem_id = "62304320731823002728660c4cf6a7e8";
        gr.update();
    }
 

View solution in original post

debendudas
Mega Sage

Hi @PapaiD ,

As the problem_id field is a reference field it only stores the sys_id of the problem record, so instead of using 

gr.problem_id = "PRB0001000", use the sys_id of the problem record (PRB0001000)

Below is the updated script:

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0010008');
gr.addNullQuery('problem_id');
gr.query();
while(gr.next()){
        gr.problem_id = "<sys_id of the Problem record PRB0001000>"; // replace it with actual sys_id
        gr.update();
}

 

 

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍!

View solution in original post

4 REPLIES 4

Prasanth Meda
Tera Contributor

@PapaiD You can use the sys_id of the Problem record to update it.

 

var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0009009');
gr.addNullQuery('problem_id');
gr.query();
if (gr.next()) {
    gr.problem_id = "<sys_id>";
    gr.update();
}

Gangadhar Ravi
Giga Sage

Hi @PapaiD 

 

You need to use sys_id of the problem record since that is reference field.

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0010008');
gr.addNullQuery('problem_id');
gr.query();
while(gr.next()){
        gr.problem_id = "62304320731823002728660c4cf6a7e8";
        gr.update();
    }
 

debendudas
Mega Sage

Hi @PapaiD ,

As the problem_id field is a reference field it only stores the sys_id of the problem record, so instead of using 

gr.problem_id = "PRB0001000", use the sys_id of the problem record (PRB0001000)

Below is the updated script:

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0010008');
gr.addNullQuery('problem_id');
gr.query();
while(gr.next()){
        gr.problem_id = "<sys_id of the Problem record PRB0001000>"; // replace it with actual sys_id
        gr.update();
}

 

 

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍!

Thank you!