Copying parent complaint case values to child complaint case

JordyZ
Mega Sage

Hi,

I'm trying to copy all field values from parent complaint case to child complaint case with this display business rule:

 

 

    if (current.isNewRecord())
    current.requesting_service_organization = current.parent.requesting_service_organization;
    current.u_agency_worker = current.parent.u_agency_worker;
    current.u_agency_worker_name = current.parent.u_agency_worker_name;
    current.account = current.parent.account;
    current.u_iban_account_number = current.parent.u_iban_account_number;
    current.consumer = current.parent.consumer;

 

 However, when I activate the script, all the parent values of the complaint case disappear.

JordyZ_0-1716465004938.png

When I deactivate the business rule, the values are back again.

JordyZ_1-1716465094443.png

 

When I create a child complaint case from the parent, it does copy over all the values, despite the values being "empty" in the parent case.

 

What can I do to fix the "empty" parent case values?

 

Thanks in advance.

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi,

I'd move your validation condition to the condition field.

 

 

current.isNewRecord() && !current.parent.nil()

 

 

 

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

	var fieldsToCopy = ["consumer","u_iban_account_number","account","u_agency_worker_name","u_agency_worker","requesting_service_organization"]; //Store as a system property

		var parentRecordGR = current.getElement('parent').getRefRecord();

	fieldsToCopy.forEach(function(field){
		current.setValue(field , parentRecordGR.getValue(field));
	})
})(current, previous);

 

View solution in original post

6 REPLIES 6

Kieran Anson
Kilo Patron

Hi,

I'd move your validation condition to the condition field.

 

 

current.isNewRecord() && !current.parent.nil()

 

 

 

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

	var fieldsToCopy = ["consumer","u_iban_account_number","account","u_agency_worker_name","u_agency_worker","requesting_service_organization"]; //Store as a system property

		var parentRecordGR = current.getElement('parent').getRefRecord();

	fieldsToCopy.forEach(function(field){
		current.setValue(field , parentRecordGR.getValue(field));
	})
})(current, previous);

 

Hi @Kieran Anson ,

 

EDIT:

Thanks for the reply. I've added all the values to a sys property like this:

JordyZ_0-1716468071881.png

and adapted the BR script accordingly:

JordyZ_1-1716468104183.png

 

But it's still not copying over the parent values to the child case.

JordyZ_2-1716468145348.png

Any ideas?

 

In your script you're not fetching the system property, you need to call the following:

var copyValuesProperty = gs.getProperty('coms.copy.values' , '');
var fieldsToCopy = copyValuesProperty.split(',')

syntax error

current.setValue(field , parentRecordGR.getValue(field_name));