Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business rule to link incident with problem

akshay707
Tera Contributor

Hi,

 

 I have created an after business rule that will automatically create a problem record once new INC is created with priority-new. Some of the details for problem record are taken itself from the same INC record.

The issue here is.How should i get this problem record getting linked with the incident automatically(getting problem "number" into "problem_id" field of incident form.I have tried the following script.Please let me know if I am missing any point.or what piece of code should I add to get this requirement done.

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


var prbgr = new GlideRecord("problem");
prbgr.initialize();
prbgr.short_description = current.short_description;
prbgr.description = current.description;
prbgr.insert();
gs.addInfoMessage("New Problem created with number :" + prbgr.number);

})(current, previous);

1 ACCEPTED SOLUTION

Inactive_Us1474
Giga Guru

You can try this in after insert BR: 

var prbgr = new GlideRecord("problem");
prbgr.initialize();
prbgr.short_description = current.short_description;
prbgr.description = current.description;
current.problem_id = prbgr.insert();
current.update();
gs.addInfoMessage("New Problem created with number :" + prbgr.number);

 

View solution in original post

7 REPLIES 7

Pooja Devkar
Mega Guru

Hello,

User after insert business rule:

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

                 var pb = new GlideRecord("problem");
                 pb.initialize();

                 pb.description = current.description;// to copy
                 current.problem_id = pb.insert();
                 current.update();
                 gs.addInfoMessage("New Problem created with number :" + pb.number);

})(current, previous);

Please mark helpful pr correct if it useful.

Thanks & Regards,

Pooja Devkar

samratgangu
Giga Contributor

Is this line current.problem_id = prbgr.insert(); setting the value of problem_id field on INC form? Someone tried?

It's not working for me. 

samratg
Tera Contributor
Is this line current.problem_id = grPrb.insert(); setting the value of problem_id field on INC form? Someone tried?It 's not working for me.
I tried current.problem_id = grPrb.sys_id; as well. But none is setting.