In this guide, we will share how to create a select list of previously created repeat group entries to use them in other repeat entries to create many to many record relationships on Salesforce.
Example form template for import:
[Example Form] Repeat to Repeat ( Many to Many ) Record Relationship.json13.0KB
Please add this JavaScript to pages where you would like to create select lists from existing repeat group entries.
// Set repeat group id for select list
var repeat_group_id = 'aac1-614e-03e2'
// Set field id from repeat that will be used as select value
var repeat_group_field_for_select_options = '1a4e-a5e3-b2de'
// Set select field for related repeat selection
var related_repeat_group_select_list_id = 'cebe-a85b-7ef3';
// Create options on page load
create_related_repeat_group_select_list_options( {} );
// Listen to repeat group changes
formyoula.form_fields[ repeat_group_id ].on( 'element:create:success', function( event, data ) {
// Create options on page load
create_related_repeat_group_select_list_options( {} );
} );
// Main function to create select options for relating repeat groups
function create_related_repeat_group_select_list_options( options ) {
// Get repeat group
var repeat_value = window.formyoula.form_fields[ repeat_group_id ].get('repeat_value');
// Set select options
var select_options = [];
// Set select option values
var select_option_values = [];
// Loop over repeat group entries
_.each( repeat_value, function( repeat_entry ) {
// Loop over repeat entry fields
_.each( repeat_entry, function( entry_field ) {
// Check field id for select options
if ( entry_field.component_id == repeat_group_field_for_select_options ) {
// Push values for select field for related repeat selection
select_options.push( entry_field.value );
// Push repeat entry id for workflow mapping
select_option_values.push( entry_field.attributes.repeat_entry_id );
}
} );
} );
// Update select list with new options
window.formyoula.form_fields[ related_repeat_group_select_list_id ].set( {
select_options: select_options.join( '\n' )
} );
}
For any questions, please contact us - [email protected] or the Formyoula in-app chat 🙂