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
Rendered Component
Workflow Arguments
Workflow Variables
Column Specifications for an Editable Grid Initialized via Workflow Activities
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.
-
Launch Workflow Composer and open the workflow. See Open the Workflow for a Sequence.
-
Double-click the first state in the workflow. In our example it is the Welcome form.
-
Drag a Sequence activity into the Entry section of the Welcome form.
-
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
-
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.)
-
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.)
-
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.)
-
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.)
-
Drag a ForEach activity below the Assign activity and specify the following properties:
- TypeArgument: Cmc.NexusCrm.Common.Entities.ContactKalyRecordList
- Value: contact.ContactKalyRecordLists
-
Drag a Sequence activity into the Body section of the ForEach activity.
-
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 -
(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)
-
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[].)