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.

Challenge:
β˜…β˜…β˜…β˜…β˜†

Steps

  1. Add component: Form Block
  2. In the Settings Panel, select the 'Jobs' Table
  3. Eject
  1. Click on the Field Group. Set Labels to 'Above'
  2. Add component: Options Picker
  3. In the Settings Panel, enter 'ExistingEmployee' as the Field.
  4. Set Type to 'Radio buttons'
  5. Set Direction to 'Horizontal'
  6. Set Default value to 'SELECT'
  7. Uncheck Alphabetical
  8. Set Options source to 'Custom'
  9. Define options:
    1. LabelValue
      Select existing employeeSELECT
      Create new employeeNEW
  1. 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. Click on the Form and set the Schema back to 'Jobs'
  2. Click on the 'Save' Button and Define actions
  3. Click the X beside each actions so that only the Validate Form and Save Row actions remain
  4. Add Action: Navigate To Screen '/jobs'
  5. Add Action: Continue if / Stop if
    1. Continue if {{ Form.Fields.ExistingEmployee }} Equals NEW
  6. 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.