Link two entities in one form

Example: Creating an employee record and linking them to a newly created job

Try it out!

Scenario

When creating a new job, you want the option of creating and linking a new employee to that job in the one form. For this example you should use the sample data supplied in the internal BudibaseDB tables.

Challenge:
★★★★☆

Steps

  1. Add component: Form Block

  2. In the Settings Panel, select the 'Jobs' Table

  3. At the very bottom of the settings panel, click Eject - this will break down the Form Block into it's constituent parts. We can see this in the component tree.

  4. Add component: Options Picker

  5. In the Settings Panel, enter 'ExistingEmployee' as the Field.


  6. Set Type to 'Radio buttons'

  7. Set Direction to 'Horizontal'

  8. Set Default value to 'SELECT'

  9. Uncheck Alphabetical

  10. Set Options source to 'Custom'

  11. Define options:

    1. LabelValue
      Select existing employeeSELECT
      Create new employeeNEW
  1. In the component tree, drag the Relationshipfield below the Options Picker
  2. Click on the Conditions tab
  3. Configure conditions: Add condition
    1. Hide component IF {{ Form.Fields.ExistingEmployee }} Equals Binding NEW
    2. Save
  1. Add component: Container
  2. Click on the Conditions tab
  3. Configure conditions: Add condition
    1. Hide component IF {{ Form.Fields.ExistingEmployee }} Equals Binding SELECT
    2. Save
  1. Add component: Headline. Set Text to 'New Employee'

  2. Add component: Field Group

  3. Click on the Form and set the Schema to 'Employees'

  4. Click on the newly added Field Group and click Update form fields

  5. Set Type to Two columns

  6. Delete the Jobs field

  1. You may also need to replace the Text Field for Address with a Long Form Field if it displays as an error.

  2. Click on the Form and set the Schema back to 'Jobs'

  3. Click on the 'Save' Button, enter the settings using the cog-icon and Define actions

  4. Click the X beside each actions so that only the Validate Form and Save Row actions remain

  5. Add Action: Navigate To Screen '/jobs'

  6. Add Action: Continue if / Stop if

    1. Continue if {{ Form.Fields.ExistingEmployee }} Equals NEW
  7. Add Action: Save Row

    1. Set Table to 'Employees'

    2. Add Column for each form field in the Employees Field Group. Set the Value to the form field bindings, e.g. {{ Form.Fields.First Name }}

    3. Add Column for the 'Jobs' column. Set Value to {{ Action 2.Saved row._id }}. This will get the _id of the Job that was saved in second action.

    4. Save your actions!

📘

Employee validation

As the select form schema is for the Jobs table, you will need to add custom validation rules to the Employee fields you want validated.

The same is also true for options that are defined by the table schema, such as Employee Level in this case.



App export

Downloads may take a few seconds.