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

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

hussainibeg
Kilo Contributor

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());   Dr ug ch u

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@hussainibeg Please see if this works.

 

// 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);
            }
        }
    }
}