The topic "ObjectCopier<>" is not available in Version 3.5.

The topic "ObjectCopier<>" is not available in Version 3.6.

ObjectCopier<>

The ObjectCopier<> workflow activity copies one object (source) to another object (target) without having to iterate through the object properties. The activity copies all properties that match in Name and Type to another object.

When you drag the ObjectCopier<> into the Designer pane, you are prompted to select the TSource and TTarget.

Source and Target Object selection

The object types for selection include:

  • Boolean
  • Int32 (default)
  • String
  • Object
  • Array of (T)
  • Browse for Types...

The only valid choice here is Browse for Types.

You should choose:

  • a class with properties,
  • an entity,
  • a SerializableDynamicObject, or
  • a RepeaterSerializableDynamicObject.
Type of Source and Target Objects Description
Same type This is typically an entity in the Anthology object model, but it can be any class with read/write properties, a SerializableDynamicObject, or a RepeaterSerializableDynamicObject.
Different types All properties that have the same Type and Name will be copied by the activity.
SerializableDynamicObject As these are dynamic objects. When writing them, the Dictionary defined properties will be created by the activity. When reading them, all properties defined in their Dictionary will be copied.
RepeaterSerializableDynamicObject

Once the TSource and TTarget are selected, the header of properties pane for the ObjectCopier<> activity displays the selected objects. You can now specify the source and target arguments to be used by the activity. For an ObjectCopier<>, the argument type must match the TSource or TTarget type.

The ObjectCopier<> activity also provides the option to exclude or include some properties in comma separated lists. By default, all properties that can be copied (they exist in both source and target and are the same name and type) will be copied.

  • If IncludedProperties are specified, only those properties will be copied (if they exist in both the source and the target)

  • If ExcludedProperies are specified, all properties not excluded will be copied. Often an Id will be excluded.

  • If both are specified, ExcludedProperties is ignored.

alert

If an existing object is populated with data and a user wants to update that object by means of another object using ObjectCopier<>, all fields in the object (source) will be copied to the target, even if the fields are empty.

For example, a form loads an editable grid with address data fields and some fields are updated, while others are left blank. If the ObjectCopier<> is used to copy the updated grid to another object, the target resulting from object copy will have the updated fields and the blank fields. The ObjectCopier<> does not check for changed values. It does not selectively copy fields that were updated. The result is that if you save this data to the database, you will be changing information you did not necessarily want to change.

To avoid this situation, make sure you are not creating a new target object. If it is first retrieved from the database and exists with the current data and you only want to update certain fields, use the Included Properties, and list them. That way the current data you do not want changed will not be changed when you save the entity.

Properties

ObjectCopier<> Properties
Property Value Required Notes
Display Name String No Specify a name for the activity or accept the default.
By default, the Display Name is "ObjectCopier<Source Object Name,Target Object Name>".
Excluded Properties String No Specify a comma separated list of properties that won't be copied. By default, no properties will be excluded.

ExcludedProperties will be ignored if IncludedProperties is specified.

Included Properties String No Specify a comma separated list of properties to include when copying. By default, all properties that can be copied (exist, and match name and type) will be copied.

ExcludedProperties will be ignored if IncludedProperties is specified.

Source Object InOutArgument<> Yes Specify an argument name of an object to copy.
Target Object InOutArgument<> Yes Specify the target argument to copy the source to.

Example: RepeaterSerializableDynamicObject

A form sequence collects information about a student's previous education. The sequence contains a Repeater control with the following layout.

Repeater Form - StudentPreviousEducation

The ObjectCopier<> activity is added to the initial workflow to copy the RepeaterSerializableDynamicObject[] to a specific StudentPreviousEducationEntity and save it. With the ObjectCopier<> there is no need to go through each property and use data dictionary keys to copy property values.

ForEach-Student

The Next transition before the End state has a Sequence containing the following activities:

  • WaitForFormBookmark (Next)

  • ForEach<RepeaterSerializableDynamicObject>

    • TypeArgument = Cmc.Nexus.FormsBuilder.Entities.RepeaterSerializableDynamicObject
    • Value = myPrevEd

    The Body of the ForEach activity contains a Sequence with ObjectCopier<>, Assign, and SaveEntity<> activities.

  • ObjectCopier<RepeaterSerializableDynamicObject,StudentPreviousEducationEntity>

    • TSource = Cmc.Nexus.FormsBuilder.Entities.RepeaterSerializableDynamicObject
    • TTarget = Cmc.Nexus.Admissions.Entities.StudentPreviousEducationEntity
    • Source Object = item
    • Target Object = userEnteredPrevEd

    The source object "item" is an instance of the RepeaterSerializableDynamicObject with the "myPrevEd" value.

    The target object "userEnteredPrevEd" is created and initialized by the ObjectCopier<>.

  • Assign

    • To = userEnteredPrevEd.StudentId
    • Value = studId (variable created by the user)
  • SaveEntity<StudentPreviousEducationEntity>

    • Entity = userEnteredPrevEd
    • ValidationMessages = formInstance.ValidationMessages

The variables in this workflow are:

Variables - StudentPreviousEducation

The arguments created by Forms Builder are:

Arguments - StudentPreviousEducation

Note: The dummy underscore arguments are automatically assigned when a workflow with Repeater control is initially created. For more information, see Repeater Workflow Arguments.

Example: SerializableDynamicObject

A form sequence collects information about a student's addresses. The sequence contains a Grid control with the following layout.

Repeater Form - Addresses

The ObjectCopier<> activity is added to the initial workflow to copy the SerializableDynamicObject[] to a StudentRelationshipAddressEntity and save it. With the ObjectCopier<> there is no need to go through each property to copy property values.

ForEach - Address

The Next transition before the End state has a Sequence containing the following activities:

  • WaitForFormBookmark (Next)

  • ForEach<SerializableDynamicObject>

    • TypeArgument = Cmc.Nexus.FormsBuilder.Entities.SerializableDynamicObject
    • Value = myAddrs

    The Body of the ForEach activity contains a Sequence with ObjectCopier<> activity.

  • ObjectCopier<SerializableDynamicObject,StudentRelationshipAddressEntity>

    • TSource = Cmc.Nexus.FormsBuilder.Entities.SerializableDynamicObject
    • TTarget = Cmc.Nexus.Common.Entities.StudentRelationshipAddressEntity
    • Source Object = item
    • Target Object = studAddr

    The source object "item" is an instance of the SerializableDynamicObject with the "myAddrs" value.

    The target object "stuAddr" is created and initialized by the ObjectCopier<>.

The variables in this workflow are:

Variables - Addresses

The arguments created by Forms Builder are:

Arguments - Addresses