Prefill Form Fields With Case Objects Using Account Lookup And Disable The Case Status Field If It Is Prefilled With The Value "New”

In this guide, we will use Account lookup and prefill the form fields with contact and case objects. And it will disable the case status field if it is prefilled with the value "New”.

Drag and drop a Salesforce Lookup, a Text and two Select fields. Rename the fields as shown below.

image

Click the pencil icon of the Salesforce Lookup field. Select “Account” as Object and rename the Label (optional).

image

Click the pencil icon of the first Select field and add select options as shown below. Save the changes.

You can use the below select options:

Prospect Customer - Direct Customer - Channel Channel Partner / Reseller Installation Partner Technology Partner Other

image

Click the pencil icon of the second Select field and add select options as shown below.

You can use the below select options:

New Working Escalated Closed

image

Click “Field Dependencies” and paste the JSON. Save the changes.

It will manage to show select options of the second Select field based on the select options selected in the first Select field.

image

Please use the code below:

{"2245-c5bf-04c9":{"Customer - Direct":["Escalated","Closed"],"Prospect":["New","Working"]}}

Note: Please change the field ID of the first Select field according to your form.

image

Drag and drop a Text, a Hidden and a Salesforce Table field inside the Repeat field and a JavaScript field outside the Repeat fields. Rename the Hidden field as shown below.

image

Click the pencil icon of the Repeat field, then click Salesforce Pre-Fill.

image

Set “Contact” as Object, “Salesforce Lookup field” as Formyoula Parent Field and “Account ID” as Salesforce Parent Field.

Set the Autofill connection to Sequence 1 as shown below and save the changes.

image

Click the pencil icon of the Salesforce Table. Set “Case” as the object and Select Table Column as shown below.

image

You can customise the table columns.

image

Click “Advanced”. Fill in the field ID of the Hidden field as Formyoula Parent Field and fill in “ContactId” as Salesforce Parent Field as shown below.

Enable the New record Button and save the changes.

image

Click the pencil icon of the JavaScript field. Paste the code and save the changes.

image

Please use this code:

// Declare a variable to store repeat_field id
var repeate_field_id = '6285-c9f7-f4d6';
// Listener for the repeat field
window.formyoula.form_fields[ repeate_field_id ].on( 'all', function( event, data ) {
  // Check if the event is prefill:success
  if ( event == 'prefill:success' ) {
    // Await for the sfdc table UI update
    setTimeout( function() {
      // Loop through all select field with data-api_name='Status'
      $( 'select[data-api_name="Status"]' ).each( function() {
        // Get the current select field
        var select_element = $( this );
        // Check if the value of the select field is 'New'
        if ( select_element.val() == 'New' ) {
          // Disable the select field
          select_element.prop( 'disabled', true );
        }
      } );
    }, 4000 ); // End timeout
  }
} ); // End listener

Note: Please change the field ID of the Repeat field according to your form.

image

Click on the "Add" button under the "Connections" column or press on the "Create a Connection" button under the "Next Step" column, or select "Add/ Edit Connections" from the "Actions" list.

image

We will create 2 salesforce connections.

Create the first salesforce connection with the Contact object.

image

Map the form fields as shown below.

image

Click “Salesforce Record Settings” and set “Repeat Group” as Use Repeat Group as shown below.

image

Create the second Salesforce connection with the Case object.

image

Click “Salesforce Record Settings” and set “Records” as Use Repeat Group as shown below.

image

Try the form. It will disable the field if the case status is "New". The user can’t edit the field.

image

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