How to copy Planned start date and Planned end date from Change Request to Change Task when state is New record?

Akkapolk
Giga Expert

Create Change Request and then Click Change Tasks -> New.

find_real_file.png

 

How to copy Planned start date and Planned end date from Change Request to Change Task when state is New record?

find_real_file.png

 

 

 

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

You could write a before Business Rule, however, the record hasn't been created yet, so those fields won't be populated until you click submit.

I'd suggest using a display business rule to do the job with the following code:

(function executeRule(current, previous /*null when async*/) {
	
	var parentChange = current.change_request.getRefRecord();
	
	if (parentChange.isValidRecord()) {
		current.planned_start_date = parentChange.start_date;
		current.planned_end_date = parentChange.end_date;
	}


})(current, previous);

find_real_file.png


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

8 REPLIES 8

Ravi T
Tera Guru

Hi 

Write  a before business Rule on change_task

Check only on Insert

In the script add the below code

 

 

  current.planned_start_date= parent.planned_start_date;

 current.planned_end_date= parent.planned_end_date;

current.update();

 

Try this and let me know if you any issues with it

Regards

Ravi

Thank you very much.

Harsh Vardhan
Giga Patron

i would not recommend here to use "current.update()" in business rule. 

Business Rule: create before business rule on change_task table and mark "Insert" check box as true. 

try with below script 

 

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

	// Add your code here
	var sdt = current.change_request.start_date;
	var edt = current.change_request.end_date;
	current.planned_start_date=sdt;
	current.planned_end_date=edt;

})(current, previous);

 

 

Thank you very much.