Problem

P1234
Tera Contributor

Hi,

 

My task is when the user open incident need to update the Description and short description and then automatically update same description & short description in the problem record.

 

I'm executing code but not working.

 

when to run :  Description : changes

                        Problem : is same : as --> problem

 

if (current.description != previous.description) {

        var problem = new GlideRecord('problem');
        problem.addQuery('sys_id', current.problem_id);
        problem.query();
        if (problem.next()) {
            problem.description = current.description;
problem.short_description = current.short_description;
            problem.update();
        }
    }
1 ACCEPTED SOLUTION

Hi @P1234 

 

Hope you are good.

 

Below is the solution for your query, basically you should use After Update Business rule.

PFA the screenshots, this particular use case is perfectly working on my PDI, hope this helps! If this helps you to resolve your query, please mark it correct and accept the solution, Thanks 🙂

 

Below is the Code:

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

    if (current.short_description.changes() || current.description.changes()) {
        if (current.problem_id) {
            var prob = new GlideRecord('problem');
            if (prob.get(current.problem_id)) {
                prob.short_description = current.short_description;
                prob.description = current.description;
                prob.update();
                gs.info("Problem updated from Incident: " + current.number);
            }
        }
    }

})(current, previous);
If you found my response helpful, please give it a thumbs-up and designate it as solution accepted to support fellow developers and admins.


Regards,
Rathan K

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@P1234 

business rule should be after update on incident

Condition: Description Changes AND Problem Field [IS NOT EMPTY]

Script is correct.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

Sorry i set the condition is same like Description : Changes , Problem : Is not empty.

 

But not working

@P1234 

did you debug business rule and see if that triggered?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @P1234 

 

Hope you are good.

 

Below is the solution for your query, basically you should use After Update Business rule.

PFA the screenshots, this particular use case is perfectly working on my PDI, hope this helps! If this helps you to resolve your query, please mark it correct and accept the solution, Thanks 🙂

 

Below is the Code:

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

    if (current.short_description.changes() || current.description.changes()) {
        if (current.problem_id) {
            var prob = new GlideRecord('problem');
            if (prob.get(current.problem_id)) {
                prob.short_description = current.short_description;
                prob.description = current.description;
                prob.update();
                gs.info("Problem updated from Incident: " + current.number);
            }
        }
    }

})(current, previous);
If you found my response helpful, please give it a thumbs-up and designate it as solution accepted to support fellow developers and admins.


Regards,
Rathan K