The CreatorCon Call for Content is officially open! Get started here.

When Incident closed the associated problem should be closed automatically...?

Jaya Chandra Re
Tera Contributor

I am creating new problem record when incident created with BR. its working as expected. but the issue is when i resolve the incident the associated problem should be closed automatically. but its my code is not working as expected. below i am sharing my script and conditions for the reference. Please any help would be appreciated. T

 

After BR - Update , Table- Incident.

JayaChandraRe_0-1714305094138.png

JayaChandraRe_1-1714305118101.png

i have added infoMessages for testing and those are triggered correctly.

 

JayaChandraRe_2-1714305156194.png

 Thanks in advance

 

1 ACCEPTED SOLUTION

Ashutosh C J
Tera Guru

Hi @Jaya Chandra Re 
Use the below script but lets try to understand few things
1) We should use gr.addQuery("sys_id", current.problem_id) because you can see problem_id is present on the incident form and when you are querying problem table, you should compare the sys_id of problem with the sys_id present in problem_id
2)You can open the dictionary of state field in problem table. Go to the choices and bring the table field. Among all the choices that are closed, only 107 is a match for problem table. Please refer the attached screenshot
3) Once you have confirmed everything as mentioned above, use the below script. It will be after update BR and condition also remains same

AshutoshCJ_0-1714313183756.png

 

 

 

    var probRcd = new GlideRecord('problem');
    probRcd.addActiveQuery();
    probRcd.addQuery("sys_id", current.problem_id);
    probRcd.query();
    if (probRcd.next()) {
        probRcd.state = '107';
        probRcd.update();
    }

 

 

View solution in original post

10 REPLIES 10

Basheer
Mega Sage

Hi @Jaya Chandra Re,

There are 2 things which you are doing wrong here:

1. You have written addQuery("problem_id",current.sys_id); ---> Here you should not use current.sys_id as it is the sys_id of the incident.

It should be addQuery("sys_id",current.problem_id);

2. There is no state model written for problem record from new to "3". 

If you do these 2 things your code should work.

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Hello Basheer,

 

There is no state model written for problem record from new to "3". 

 I am new to ServiceNow Development, i am not getting correctly what you trying say, could you please explain a bit more for me. 

as per your responce i have updated sys_id , state as well. still my code is not working.

i am updated with gr.state = "107";

Sohail Khilji
Kilo Patron

Try this code :

var gr = new GlideRecord('problem');
gr.addActiveQuery();
gr.addQuery("sys_id",current.problem_id);
gr.query();
if(gr.next()){
gr.status ='3';
gr.update();
}

 

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hello Sohail,

 

Its not Working