Assinging a specific database value to a checkbox

I want to add a Task to the Tasks table - each Task can be assigned to a Department. The Departments come from the Department table - there are currently only two departments - Marketing and Sales.

I want to use Checkboxes to decide whether a Task belongs to Marketing, Sales or both.

I assume I need to use Custom States somehow (assign Custom state to the Pop-up?), which I can do to make a yes/state - but I can’t work out how to get the Checkbox to mean that a particular Database value - i.e. Sales - is saved to the database when the Pop-up is eventually submitted.

(Note I will probably remove the “Sales & Marketing” checkbox and just say that selecting both Checkboxes means both departments.)

This is probably a straightforward one but I can’t work it out.

I can think of a few solutions, depending on how your data is saved.
If it is saved as a list of texts, you can add the check boxed ones to the list for each one that is true.

If saved as yes/no solutions in the data, then simply change the variables based on if they are checked or not.

I like the text options as a list personally. As you add more departments, or if added manually, it will be easier to recall. I use this for item categories and for adding cities on my item rental platform. You can also use option sets to avoid typos when calling on those variables.

Sorry I am still kinda stuck here. I originally had the Departments as a Data Type of their own, but I changed it to an Option Set to make it a bit simpler. But i can’t see how to change the State of the Pop-Up I use to add a Task to have the value of one of the options from the option set. I think I am missing something fundamental about how you do this…

As for using option sets, once you click marketing, you then have to click beside it and select another option about the marketing, usually it’s name or something.

As for states, when adding a workflow step, click “element actions” and then “set state” to change the state of your popup (assuming you created a state for it first).

Once you’ve done all this a few times it’ll feel more natural and will make sense. I get it.

So I managed to get there, and now when I select Sales or Marketing (which are taken from Option Sets), the correct Value is stored in the database.

I would like to remove the “Sales and Marketing” checkbox and wonder if it is possible to have the State of an Element be two values at the same time? So, if Sales and Marketing are checked at the same time I could save both values - i.e. the Task is assigned to both departments.

If not, how would one save both Departments? I changed the Departments field in the Tasks table to be a list…

Maybe something like this?

[edit] you could also use RG’s for this, in that way, if you set everything correctly, you will have less rework in the future if the number of departments change

1 Like

I personally wouldn’t go down the route of custom states for this one. First, as @alex.p mentioned, if you have a multi-line input for task and a single state selection for responsible this won’t work as it’s mixed data grain. Hard to tell this from your screenshot.

But if it’s only allowing a single task your grains are good. So what you next probably should do is in your workflow create three separate DB inserts/updates: one for inserting the task to Marketing, one for inserting it to Sales, and one for inserting it to Marketing and Sales. Then add conditional “Only when” expressions to fire the respective DB action only when that radio button/checkbox is selected by the user.

1 Like

So I went for the three workflows (4 actually, since you also have the option to assign a Task to a specific person rather than a dept.). It works but of course won’t scale if one wants to add more depts. but I’ll work that out later.

However, I now have weird behaviour in the Repeating Group table that shows the data. Every time I add a Task (of any type), I also get a blank Task appearing in the RG. The data in the database table is actually correct, but I can’t see why these phantom rows are appearing.

Even weirder, when I refresh the page, the phantom rows disappear.

Any ideas?

I’m also realising that this way of doing things makes editing the Tasks a bit tricky too. I feel like I have gone the wrong way on this one!

Correct, this solution scales more manually. This is because your radio buttons / checkboxes for department type can contain more than a 1:1 relationship and are “abnormal” in that respect. Adding more departments will require also adding more DB action handlers every time.

For the RG, would you mind sharing your Data Source expression? Sometimes a null row thrown in there can be the result of a merge or append action.

The Data Source expression is simple: Search for Tasks.

I think it has something to do with the Custom States that are being set when I use the above checkboxes, as when I don’t use them (assigning a specific person rather than using a checkbox) then only one row is created.

This topic was automatically closed after 70 days. New replies are no longer allowed.