Salesforce Select Auto Record Selection Based on Custom Date Logic

This guide will demonstrate how to auto-select a Salesforce Select field record based on custom date logic.

image

Please add a Salesforce Select field on your form page and select the Event object. Select the following display fields - Subject, StartDateTime and EndDateTime.

Please enable the “Trigger Salesforce Select On Page Load” option on the builder side:

image

Add the following JavaScript to your form and update the field Id and set “JavaScript Load Delay (Milliseconds)” to 0.

image
// Listen to Salesforce Select render success event
window.formyoula.form_fields[ '92ea-3c5a-d674' ].on( 'lookup:results:render:success', function( options ) {
  // Loop over all records
  for ( record of options.records ) {
    // Get formatted dates
    var start_date = moment( record.StartDateTime ).format( 'MM/DD/YYYY' );
    var end_date = moment( record.EndDateTime ).format( 'MM/DD/YYYY' );
    var today = moment();
    // Get date difference in months
    var difference_in_months = today.diff( start_date, 'months' );
    // Check months difference logic
    if ( difference_in_months < 1 ) {
      // Update Salesforce Select with the correct record Id
      this.set( { value: record.Id, name: options.record_name_value_map[ record.Id ] }, { silent: false } );
      // Break loop
      break;
    }
  }
} ); // END Salesforce Select event listener

Example form template:

[Example Form] Auto Event Selection Record Based On Dates.json3.6KB

For any questions, please contact us - at [email protected] or the Formyoula in-app chat 🙂