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

Anurag Tripathi
Mega Patron
Mega Patron

try this

 

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


var prbgr = new GlideRecord("problem");
prbgr.initialize();
prbgr.short_description = current.short_description;

prbgr.parent=current.sys_id;
prbgr.description = current.description;
prbgr.insert();
gs.addInfoMessage("New Problem created with number :" + prbgr.number);

})(current, previous);

-Anurag

vinothkumar
Tera Guru

You have to add current.problem_id = prbgr.sys_id; in your business rule. 

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

 

Yes It worked. Will you please tell me what exactly happened in you code?