Update multiselect fields

I have doctype A and doctype B, both contain a table multiselect.
Doctype A has a multiselect field linked to doctype B and Doctype B has a multiselect field linked to doctype A. I want the tables to be updated when adding a value to either multiselect field. I basically want to link products to a certain person or a certain person to certain products. It has to be multiselect since one product can be linked to dozens of people or one dozens of products to one person.

I am struggling to set it up correctly since I am not sure how to iterate over the entries within the table. Whatever python code/method I am using, it isnt working correctly.

Any advise on how to set it up properly?