- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 04:56 AM
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.
i have added infoMessages for testing and those are triggered correctly.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 07:08 AM - edited 04-28-2024 07:09 AM
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
var probRcd = new GlideRecord('problem');
probRcd.addActiveQuery();
probRcd.addQuery("sys_id", current.problem_id);
probRcd.query();
if (probRcd.next()) {
probRcd.state = '107';
probRcd.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 05:34 AM
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 mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 06:29 AM
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";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 05:53 AM
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....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 06:18 AM
Hello Sohail,
Its not Working