How to Update on Incident table from Problem table ?

pranjal32
Tera Contributor

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 .

 

var inc = new GlideRecord('incident');
inc.addEncodedQuery('number=INC0007002');
inc.query();
if(inc.next()){
    var prb = new GlideRecord('problem');
    prb.addEncodedQuery('first_reported_by_taskLIKEINC0007002');
    prb.query();
    if(prb.next()){
        inc.short_description = prb.short_description;
        inc.category='hardware'
        inc.update();
    }
}
6 REPLIES 6

Md Atif Hussain
Tera Contributor

Hi @pranjal32 

u can achieve you requirement by using after business rule and select Problem table

 

and in Condition you have to select state changes 

I am attaching screenshot 

 

(function executeRule(current, previous /*null when async*/ ) {

        // Add your code here
        var gr = new GlideRecord('incident');
        gr.addQuery('problem_id', current.sys_id);
        gr.query();
        while (gr.next()) {
            gr.short_description = current.short_description;
            gr.update();
        }

 

Dr Atul G- LNG
Tera Patron
Tera Patron

HI @pranjal32 

 

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 ?

 

Atul: May i know what is use case of this, in this case you will get multiple Incident with same Short description , which may be confusing for filter later on.

*************************************************************************************************************
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]

****************************************************************************************************************