1. Betty Blocks Documentation
  2. Use-case guides
  3. Creating, updating, deleting, and assigning data (CRUD)

Assigning a task

Use case 4 of a 4-part series. In this article, you'll learn how to assign a task to some role in your application.

Note: Before we start it's worth mentioning that to complete adding tasks properly, there is a pre-created Task overview page with a data table that contains all our tasks.

Setting up models

For this last use case, make sure to also create a new model called Employee (add properties like 'Name' and 'Password'). We'll be assigning an employee to a task; so create a relation between the models:

1) Go to the data model overview and open the schema view.

2) Find your 'Employee' and 'Task' models.

3) Connect them together so that in the result you have: 'One Employee has many Tasks'

Don't forget to set the permissions properly for the models, since we're not working with live data you can set them to public.

Assigning a new user

To assign a new user, let's go back to the first use case in this series.

1) Go to the page builder and open the New tasks page.

2) This time, make sure that the beta forms are enabled this allows us to create the assign functionality more easily.

3) Delete your old create form and drag the new Create form on the page.

4) A pop-up appears in which we have to select the Task model.

5) We can now (if the relation has been created properly) select not only our properties as we did in the first use case but also an employee.

6) Click on Save to save the new form.

The employee, by default, is selected via their ID. Ideally, we select this via an employee's name, to do this select the Autocomplete component. You can now find the option 'Label for options' and select the employee, then choose the name and press Select to use an employee's name instead of his ID when assigning tasks.

When you run the application by clicking on the play button in the top-left corner, you'll likely encounter an error.

Before trying out if the form works, for this example, let's disable the permissions for the action behind the form. To do this go select the form itself and click on the Edit permissions next to the action option.

This allows us to turn off the private action, making the form accessible to everyone.