In this guide, we will explain how to link one repeat group records to another repeat group records.
Inside the first repeat group, please create a hidden field that will be the unique value for each repeat group entry recorded on Salesforce as an external key for Upsert.
For example, Contact Unique ID:
We can use the following JavaScript code to create unique IDs for each Contact repeat group entry record.
window.formyoula.form_fields['Contact Unique ID'].set({ value: 'DHR-' + Math.trunc(Math.random() * 100000) });
Inside the other repeat group, please add an empty Select List that will be populated by the previous repeat group entry Contact Unique IDs.
Please add the following JavaScript that will get all Contact Unique IDs from the first repeat group and populate the second repeat group Contact Unique IDs Select list.
// Get related record repeat entry
var repeat_group_values = window.formyoula.form_fields['1632-6e44-c7e8'].get('repeat_value');
// Create select options
var related_recoord_options = '';
// Loop over all repeat entries and update select list with related record options
for ( var i = 0; i < repeat_group_values.length; i++ ) {
// Set repeat entry
var repeat_entry = repeat_group_values[i];
// Loop over fields
for ( var i2 = 0; i2 < repeat_entry.length; i2++ ) {
// Get repeat entry field
if ( repeat_entry[i2].component_id == '9f7a-1ec2-33c4' ) {
// Set option for related records
related_recoord_options += repeat_entry[i2].value + '\n';
}
}
}
//Remove the last linebreak
related_recoord_options = related_recoord_options.slice(0,-2);
// Update record select list with options
window.formyoula.form_fields['a5f6-da6b-1c63'].set({ select_options: related_recoord_options });
We will need to create 2 Salesforce Connections for the second repeat group that will create tasks and link them with one of the Contact records created in the first repeat group.
First connections will be necessary to find the Contact records based on the Contact Unique ID so that we relate them in the next connection.
The object will be Contact.
In record options we will use the Task repeat group, upsert based on the Contact Unique IDs Select list and we will disable the connection Salesforce record updates as this connection will only be used to find the necessary Contact records for the next connection mappings.
We also need to create a mapping to make sure the Upsert understand the Salesforce and Formyoula field relation.
On the second connection for the Task object, we can map the previous connection as the related field.
This setup will allow us to create any number of Contact records in the first repeat group and select the specific Contact from the first repeat group as the Task related Contact in the second repeat group.
For any questions, please contact us - [email protected] or the Formyoula in-app chat 🙂