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

TanujB
Tera Contributor
var x=new 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());
    x.update(x.problem_id.short_description=x.rfc.short_description);
}
5 REPLIES 5

J Siva
Tera Sage

Hi @TanujB 

Try the below script..

var inc = new GlideRecord('incident');
inc.addQuery('number','INC0000506');
inc.query();
if(inc.next()){
inc.short_description = inc.problem_id.short_description;
inc.update();
}

 Regards,.siva

Chaitanya ILCR
Mega Patron

Hi @TanujB ,

 

you want to update the change short description? then use this script

var incGr = new GlideRecord('incident');

if (incGr.get('number', 'INC0000011')) {
    gs.info(incGr.problem_id.getDisplayValue());
    gs.info(incGr.problem_id.short_description);
    var chgGr = incGr.rfc.getRefRecord();
    if (chgGr.isValidRecord()) {
        chgGr.short_description = incGr.problem_id.short_description;
        chgGr.update();
    }
}

 

if you want to update the problem short description from change short description use this

 

var incGr = new GlideRecord('incident');

if (incGr.get('number', 'INC0000011')) {
    gs.info(incGr.problem_id.getDisplayValue());
    gs.info(incGr.problem_id.short_description);
    var prbGr= incGr.problem_id.getRefRecord();
    if (prbGr.isValidRecord()) {
        prbGr.short_description = incGr.rfc.short_description;
        prbGr.update();
    }
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Aniket Chavan
Tera Sage
Tera Sage

Hello @TanujB ,

 

You're trying to copy the Problem's short description into the Change Request's short description so please you the script below and see how it works for you and the logs will help you to understand the execution as well, so try to debug if anything goes wrong based on the logs also make sure your change req record reference is stored in rfc field only if you're using any other like "Parent" so just update that in the below script.

var incGR = new GlideRecord('incident');
if (incGR.get('number', 'INC0000011')) {
    
    var probGR = incGR.problem_id;
    var rfcGR = incGR.rfc; // Assuming 'rfc' is a reference to Change Request
    
    if (probGR && rfcGR) {
        var changeGR = new GlideRecord('change_request');
        if (changeGR.get(rfcGR)) {
            changeGR.short_description = probGR.short_description;
            changeGR.update();
            gs.info('Updated Change Request short description with Problem short description.');
        } else {
            gs.info('Related Change Request not found.');
        }
    } else {
        gs.info('Either Problem or RFC reference is missing.');
    }

} else {
    gs.info('Incident not found.');
}

 

🔹 Please mark Correct if this solves your query, and 👍 Helpful if you found the response valuable.

 

Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024

Hello @TanujB ,

 

Just wanted to check in to see if my earlier response helped you out or if you're still facing any issues. If your query is resolved, it would be great if you could mark my reply as helpful and accept it as the solution — that way it can also benefit others who come across the thread later.

 

Also, if you found any other responses helpful, feel free to mark those as helpful too. You can even accept multiple solutions if they contributed to resolving your issue.

 

Let me know if you need anything else!

 

Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024