Add values to multiple choice

Hi

I have a Knack database with connected tables as a one to many. It is 1 User and many Forms. During an iteration I am trying to add more Forms to the User. The problem I am having is it replaces all the Forms connections with the new one. If I try adding the current values then the new one it only takes the last form from the current and the new one and removes the rest.

Any pointers would be appreciated.

Thanks

You’ll most likely need to read the existing values, append your new value and update with the resulting merged data. The update appears to be “destructive” which means it replaces what is already there with the new data.

3 Likes

Thanks Alex, yes this is the approach I have been trying to take but I’m struggling to figure out how to build the array. If I add the IDs separately it works but if I try to map it comma separated it fails…

This works…
image

This fails…
image

try to make an array with add(emptyarray;id1; id2)

usually the input to map a list of items needs to be in an array so a comma delimited list won’t work – it depends on the underlying API but I have found that to be the case usually.

3 Likes

Yep tried that as well, I created an array just with IDs in it but it wouldn’t accept that either, starting to get rather annoying!! I’ll persist.

Sorry that does work, I had something in the wrong place!!

What was the exact expression you used? Feel free to copy and paste it here and use the code format after you paste it here. Could be useful for others.

3 Likes

Hi sure I can share the solution, but this is only my second flow built in Make so I am sure there could be a better way and I’d be glad of any pointers…

It connects with an App in Knack which is very limited in its processing functions hence I needed to use something outside.

As background this is part of an on-boarding process for new staff members. There are different ‘types’ of staff. They can be home carers or service providers etc… When they join they need to complete a number of forms and training. These in some cases expire and need to be renewed.

In the Knack solution there is the Staff table which includes the type of staff and they can be one or more types.

There is then a form type table. Each form type can be assigned to one or more staff types. The form type holds the meta data for the period the staff has to compete the form or training and the period it has until expiry.

Then there is the form table itself and these are created when the staff member joins depending on their type.

Step 1.

Watch the staff table for new records

Step 2.

Read and iterate the staff types

Step 3.

The staff types have some html so mark this down.

Step 4.

Search for all the form types which include the staff type.

Step 5.

Iterate the Form types

Step 6.

Create the form record and link to the Staff record

Step 7.

Here is where I started to have issues because I couldn’t find a way for a variable to reference itself and therefore add new values to an array.

So here I get the staff record again and read what forms it has.

Step 8.

Take the form IDs already in the staff record and add the new form ID…

add(map(existing forms (raw)[]; “id”); newform.id)

I found the Make documentation on this very poor. Actually quite poor in general.

One bit I still need to add here is a check to see if the form has already been added because a staff can have many types and different staff types will have some of the same forms.

Step 9.

Set the forms array field in the staff record to the variable in step 8.

It then iterates around and reads the forms out of the staff record again and adds the new one.

This isn’t very efficient and I’d like to think there is a better way…

2 Likes