Assigning a Business Object

Assigning a Business Object is by reference.

personDataField = car.owner; // Business Object assigned to data
                             // field by reference
personDataField.age = 25;    // Also affects car.owner.age
var tempPerson = personDataField;	// Business Object assigned to
                                 // local variable by reference
tempPerson.name = "Bob";			// Also affects personDataField.name
var owner = com_example_refval_Factory.createPerson();
car.owner = owner;
owner.name = "Ludwig"; // Also affects car.owner.name;
Note: If a Business Object is assigned, but is already contained in another Business Object’s containment, it is automatically removed from that containment. It is impossible for an object to be contained by two containers at the same time. If this is not the desired behavior, make a copy of the object first using the ScriptUtil.copy(…) utility, see Create a Copy of a Business Object .

In the next example, although all assignments are by reference (there is only ever one Address), the final line of the script removes the Address from Customer, leaving Customer with no Address:

var address = com_example_refval_Factory.createAddress();
customer.address = address;
account.address = customer.address; // Removes address from
                                    // customer

If this script is modified to use ScriptUtil.copy(…), account and customer end up with independent copies of the address:

var address = com_example_refval_Factory.createAddress();
customer.address = address;
account.address = ScriptUtil.copy(customer.address);
// Creates an independent Address