How to create Problem from Incident by REST API or Script.

Viral Patel
Kilo Contributor

Hi,

I have many incidents in one Servicenow instance. I want to create Problem from one incident and link other related incidents to this problem. I want to do this all not by UI. But by any REST API or by any Script triggered on REST API call.

Please help me to guide on how can I create problem from Incident by Script or API. and also for linking.

 

Thanks in Advance,

Viral Patel

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

You can configure business rule on incident table to create problem.

Use below business rule script to create problem from master incident and related same problem to child incidents.

 

find_real_file.png

 

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

	// Add your code here
	
	var prb = new GlideRecord('problem');
	prb.initialize();
	prb.short_description = current.short_description;
	prb.description = current.description;
	prb.cmdb_ci = current.cmdb_ci;
	prb.problem_state = "1";
	prb.assignment_group = current.assignment_group;
	var pr = prb.insert();
	current.problem_id = pr;
	var child = new GlideRecord('incident');
	child.addQuery('parent_incident',current.sys_id);
	child.query();
	while(child.next()){
		
		child.problem_id = pr;
		child.update();
		
	}
	

})(current, previous);

 

Regards,

sachin

View solution in original post

1 REPLY 1

sachin_namjoshi
Kilo Patron
Kilo Patron

You can configure business rule on incident table to create problem.

Use below business rule script to create problem from master incident and related same problem to child incidents.

 

find_real_file.png

 

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

	// Add your code here
	
	var prb = new GlideRecord('problem');
	prb.initialize();
	prb.short_description = current.short_description;
	prb.description = current.description;
	prb.cmdb_ci = current.cmdb_ci;
	prb.problem_state = "1";
	prb.assignment_group = current.assignment_group;
	var pr = prb.insert();
	current.problem_id = pr;
	var child = new GlideRecord('incident');
	child.addQuery('parent_incident',current.sys_id);
	child.query();
	while(child.next()){
		
		child.problem_id = pr;
		child.update();
		
	}
	

})(current, previous);

 

Regards,

sachin