How to Update on Incident table from Problem table ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 03:11 AM
How can I achieve this scenario -- If a Problem Record is related to a Particular Incident then Incident record's short_description should get updated as same as the related problem record's short_description ?
I have done it for one record I want to do it for multiple record .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:45 AM
Hi @pranjal32 , try below code
var prb = new GlideRecord('problem');
prb.addNotNullQuery('first_reported_by_task');
prb.query();
while (prb.next()) {
var inc = new GlideRecord('incident');
inc.addQuery('sys_id', prb.getValue('first_reported_by_task'))
inc.query();
while(inc.next()) {
inc.short_description = prb.short_description;
inc.category='hardware'
inc.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:51 AM
Hi @pranjal32
Please have a look in to Incident properties:
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:53 AM
Hi @pranjal32 ,
You can use below script
var inc = new GlideRecord('incident');
inc.addEncodedQuery('your_query_here'); //active true incidents
inc.query();
while (inc.next()) {
var prb = new GlideRecord('problem');
prb.addEncodedQuery('first_reported_by_task=' + inc.number);
prb.query();
if (prb.next()) {
inc.short_description = prb.short_description;
inc.category = 'hardware';
inc.update();
}
}
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:56 AM
Hi @pranjal32
I hope below code will help you to achieve your scenario
var inc = new GlideRecord('incident');
inc.addEncodedQuery('YOUR_CONDITION_HERE');// Add your specific condition like type is email, phone whatever
inc.query();
// Loop through matching Incident records
while (inc.next()) {
var prb = new GlideRecord('problem');
prb.addQuery('first_reported_by_task', inc.number);
prb.query();
// If a related Problem record is found, update the Incident
if (prb.next()) {
inc.short_description = prb.short_description;
inc.category = 'hardware';
inc.update();
}
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks