The Zurich release has arrived! Interested in new features and functionalities? Click here for more

I want to update problem id short des into change request short desc using background script

hisbyefat
Mega Explorer

GlideRecord('incident');x.addQuery('number','INC0000011');x.query();if(x.next()){ gs.info(x.problem_id.getDisplayValue()); gs.info(x.problem_id.short_description.getDisplayValue());   GlideRecord('incident');x.addQuery('number','INC0000011');x.query();if(x.next()){ gs.info(x.problem_id.getDisplayValue()); gs.info(x.problem_id.short_description.getDisplayValue());   

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@hisbyefat 

// Update Change Request short description with Problem short description (via Incident)

var cr = new GlideRecord("change_request");
cr.addNotNullQuery("incident");   // only CRs linked to an incident
cr.query();

while (cr.next()) {
    var inc = new GlideRecord("incident");
    if (inc.get(cr.incident)) {
        if (inc.problem_id) {
            var prb = new GlideRecord("problem");
            if (prb.get(inc.problem_id)) {
                cr.short_description = prb.short_description;
                cr.update();
                gs.print("Updated CR: " + cr.number + " with Problem short desc: " + prb.short_description);
            }
        }
    }
}