Autopopulate all affected cis in related list of change request to change task related list affected cis

Harsha Pandey
Tera Expert

Hi,

In change request, there is already a related list of affected cis, there can be multiple affected cis in this related list.

I want to populate all those affected cis in related list of change task affected cis. These change tasks are getting populated in change request at implement state in related list 'Change Tasks'.

Note: I can already see a related list tab in change task for affected cis, as we do not want another related list tab for affected cis.

Please suggest a business rule for this as we do not want a new relationship !!!!!!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use this logic to link those affected Cis to Change task

BR: After Update on Change Request

Condition: State [Changes to] Implement

Script:

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

	// Add your code here
	var rec1 = new GlideRecord("change_task");
	rec1.addQuery("change_request", current.getUniqueValue());
	rec1.query();
	while(rec1.next()){
		var gr = new GlideRecord("task_ci");
		gr.addQuery("task", current.getUniqueValue());
		gr.query();
		while(gr.next()) {
			var rec = new GlideRecord("task_ci");
			rec.initialize();
			rec.task = rec1.getUniqueValue();
			rec.ci_item = gr.ci_item;
			rec.insert();
		}
	}

})(current, previous);

Regards
Ankur

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use this logic to link those affected Cis to Change task

BR: After Update on Change Request

Condition: State [Changes to] Implement

Script:

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

	// Add your code here
	var rec1 = new GlideRecord("change_task");
	rec1.addQuery("change_request", current.getUniqueValue());
	rec1.query();
	while(rec1.next()){
		var gr = new GlideRecord("task_ci");
		gr.addQuery("task", current.getUniqueValue());
		gr.query();
		while(gr.next()) {
			var rec = new GlideRecord("task_ci");
			rec.initialize();
			rec.task = rec1.getUniqueValue();
			rec.ci_item = gr.ci_item;
			rec.insert();
		}
	}

})(current, previous);

Regards
Ankur

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

Hi Ankur,

I tried with this script but it is not working. The related change task should have the same affected cis in their related list as it is in change request affected cis related list.

Could you please suggest what could be done.

We want the affected ci related list of both change request and related change task to be same, if 4 cis are attached to change request affected ci related list, same cis should get attached to change task affected ci related list.

Thanks,

 

Hi,

script will work fine

Where have you written that script and share your latest script and the screenshot of where have you written it? i.e. business rule etc

Regards
Ankur

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

I have done it through business rule.