Copy Description from the Problem to Incidents

Community Alums
Not applicable

Hi,

I am working on a scenario where the Description field from a Problem record will be copied to associated incident records once the problem record is saved. I have done everything but the Description in Incident records is not getting updated with the Description of the problem record once is saved the problem record. Kindly help.

 

1.png

 

2.png

 

3.png

 

4.png

 

5.png

 

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

	var gr = new GlideRecord("incident");
	gr.addQuery('problem_id', '3D62304320731823002728660c4cf6a7e8');
	gr.query();
	while(gr.next()){
		gr.description = current.description;
		gr.update();
	}

})(current, previous);

 

Regards

Suman P.

1 ACCEPTED SOLUTION

Abhishek_Thakur
Mega Sage

Hello @Community Alums ,

You need to create a BR on after insert/Update on problem table and follow the below script that will help you. I tried in my PDI it is working as expected.

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

	// Add your code here
	var inc = new GlideRecord("incident");
	inc.addQuery("problem_id",current.sys_id);
	inc.query();
	if(inc.next()){
		inc.description=current.description;
	}
	inc.update();

})(current, previous);

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

View solution in original post

5 REPLIES 5

Abhishek_Thakur
Mega Sage

Hello @Community Alums ,

You need to create a BR on after insert/Update on problem table and follow the below script that will help you. I tried in my PDI it is working as expected.

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

	// Add your code here
	var inc = new GlideRecord("incident");
	inc.addQuery("problem_id",current.sys_id);
	inc.query();
	if(inc.next()){
		inc.description=current.description;
	}
	inc.update();

})(current, previous);

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

Community Alums
Not applicable

Hi @Abhishek_Thakur ,

Thank you, it worked, but I have a question please. How is that if condition worked even though there are many incidents.

Regards

Suman P.

Hello @Community Alums ,

You can use the "while" istead of "If" for the many incidents.

 

Please mark my answer as accepted solution and give thumbs up.

Hello @Community Alums ,

If my given code worked for you, could you please accept the solution and give thumbs up. So, that it can help  other if they will stuck in the same scenario.