CRM Grid for One-to-Many Relationships

You can use the Grid component to create a form to retrieve/save records that are in a one-to-many relationship. In a one-to-many relationship, the parent can have a single child record, multiple child records, or zero child records. The child cannot have more than one parent record.

In the example below, the grid is used to populate child records for a CRM Contact entity. The child records contain hobbies that are entered on the rendered grid.

To initialize this type of grid, workflow activities need to be used rather than OData queries. The workflow activities use the "vm.models.HobbyGrid" Model property assigned in the Grid Property Settings. The rendered grid enables the user to add child records (hobbies) for a given parent record (a contact named "Kaly").

Control Property Settings

Form Properties

Rendered Component

Rendered Grid with One-to-Many records

Workflow Arguments

Workflow arguments - One-to-Many grid

Workflow Variables

Variables - One-to-many grid

Column Specifications for an Editable Grid Initialized via Workflow Activities

Column specifications

Initializing the Grid Using Workflow Activities

The first state in the form sequence workflows needs to be modified to initialize the grid for the child records.

  1. Launch Workflow Composer and open the workflow. See Open the Workflow for a Sequence.

  2. Double-click the first state in the workflow. In our example it is the Welcome form. Closed

    Welcome State

  3. Drag a Sequence activity into the Entry section of the Welcome form.

  4. Drag a LookUpContact activity into the new Sequence and specify the following properties:

    • ContactId: contactIId (This is a local variable of type Int32.)
    • Display Name: Specify a name or accept the default.
    • UserName: formInstance.UserName

    Closed

    lookupcontact

  5. Drag a GetEntity activity below the LookUpContact activity and specify the following properties:

    • Type: <Contact> (Use the "Browse for Type" option to find this type.)
    • EntityId: contactId (This is a local variable of type Int32.)
    • Result: contact (This is an In/Out argument.)

    Closed

    Get Entity Contact

  6. Drag a GetRelatedEntity activity below the GetEntity activity and specify the following properties:

    • Type: <Contact> (Use the "Browse for Type" option to find this type.)
    • ParentEntity: contact (This is an In/Out argument.)
    • RelatedEntityName: "ContactKalyRecordLists" (This is the logical identifier of the related entity that can be retrieved.)

    Closed

    GetRelatedEntity

  7. Drag an Assign activity below the GetRelatedEntity activity and specify the following properties:

    • To: cnt (This is a local variable of type Int32.)
    • Value: 0 (This value initializes the grid.)

    Closed

    Assign

  8. Drag another Assign activity into the Sequence and specify the following properties:

    • To: LocalHobbyGrid (This is a local variable of type Int32.)
    • Value: New ContactKalyRecordList(contact.ContactKalyRecordLists.Count - 1){}
      (This a local variable of type  Cmc.NexusCrm.Common.Entities.ContactKalyRecordList[]. It associates the child records with the parent record.)

    Closed

    Assign

  9. Drag a ForEach activity below the Assign activity and specify the following properties:

    • TypeArgument: Cmc.NexusCrm.Common.Entities.ContactKalyRecordList
    • Value: contact.ContactKalyRecordLists

    Closed

    ForEach

  10. Drag a Sequence activity into the Body section of the ForEach activity.

  11. In the Sequence (in the Body section of the ForEach activity), drop an Assign activity for each row in the following table and type the indicated values:

    "To" Field Value
    LocalHobbyGrid(cnt) New ContactKalyRecordList
    LocalHobbyGrid(cnt).KalyHobby item.KalyHobby
    LocalHobbyGrid(cnt).KalyHobbyStartDate item.KalyHobbyStartDate
    LocalHobbyGrid(cnt).OtherReason item.OtherReason
    cnt cnt + 1
  12. (Optional) Drag a LogLine activity below the Sequence in the Body section of the ForEach activity and specify the following properties:

    • Level: Information
    • Text: Newtonsoft.Json.JsonConvert.SerializeObject(LocalHobbyGrid,Newtonsoft.Json.Formatting.Indented)
  13. Drag an Assign activity below the LogLine activity and specify the following properties:

    • To: HobbyGrid (This is the name of the In/Out argument of type ContactKalyRecordsList[].)
    • Value: LocalHobbyGrid (This is the name of the variable of type ContactKalyRecordsList[].)

    Closed

    Assign