A script to create a number of related records based on a selection can come in one of several variants (switch context, use a portal, use a magic key ...)
Let's choose the one that requires the least amount of preparation. Let your checkbox field be A::checkbox
Set Variable [ $selectionList ; A::checkbox ]
If [ IsEmpty ( $selectionList ) ]
Set Variable [ $selectionCount ; ValueCount ( $selectionList ) ]
Set Variable [ $idA ; TableA::_kpn_id ]
Set Bariable [ $qty ; TableA::quantity ]
Go to Layout [ B ( TableB ) ]
Exit Loop if [ Let ( $i = $i + 1 ; $i > selectionCount ) ]
Set Field [ TableB::_kfn_id_TableA ; $idA ]
Set Field [ TableB::_kfn_id_TableC ; GetValue ( $selectionList ; $i ) ]
Set Field [ TableB::quantity ; $qty ]
Note that the script copies the qty into the join table, to capture that value at the time of creation.
Another consideration is to avoid duplicates, i.e. add the same C record twice to an A record.
In the future, try to not use abstract names like A, B and C. Describing your real-world scenario may give valuable clues that aid in finding the best (or most appropriate) solution.
No need to loop through the selected values to create related records if you use the "Check boxes with scroll bars II" example in this teaching file:
It may not look like it, but this example does support the many to many relationship that you describe, but it rearranges it in Manage | Database in order to make the act of creating the Join table (Table B in your example) record very simple.
Note that this isn't a real check box group formatted with a value list, but rather a portal set up to look and function as though it were such a field. The portal makes the scroll bar option possible should you need such an option.
Thank you for your prompt response
Bottom line then, it is possible to do then!
I see you your point about using abstract names it is a bit confusing so if it is not an imposition herewith the real life scenario:
I have Table's named 'LineItems', 'FlatRateFringes' and 'ProjectFringes'. I would like to click on a pop-over button in the 'LineItems' row, and have it display a 'value list' of options which is derived from the values prepopulated in 'ProjectFringes'. The way I have this currently set-up to be displayed on the popover is by using the FlatRateFringes::_kfn_id_ProjectFringes field, formatted as a 'checkbox' list.
Once the selection(s) are made, I would then like to run a calculation using the values from (LineItems::QTY * LineItems::X * ProjectFringes::Value) and then have these result(s) stored as related record(s) to the original LineItem record. I would also like it if it were possible that if the value in the checkbox is unselected, then I need that related record to be deleted.
'LineItems::_kpn_id' = 'FlatRateFringes::_kfn_id_LineItems'
'ProjectFringes::_kfn_id' = 'FlatRateFringes::_kfn_id_ProjectFringes'
Value List = 'ProjectFringes::_kpn_id and ProjectFringes::FringeName'
I hope that it is a bit clearer and thanks again.
Once the selection(s) are made, I would then like to run a calculation using the values from (LineItems::QTY * LineItems::X * ProjectFringes::Value) and then have these result(s) stored as related record(s) to the original LineItem record.
In my example, you select the entries to be turned into related records, and have the calculation take place by way of an auto-enter option – or a calculation field; it depends on whether the pertinent ProjectFringes value can change over time, and if you want/must capture the value at this point in time.
(Think Invoicing and product prices; if within a line item you'd reference the product price (by using a calculation field), any subsequent price change would falsify old invoices. But if you copy the price, such a changes has no impact.)
I would also like it if it were possible that if the value in the checkbox is unselected, then I need that related record to be deleted.
Almost anything is possible; the constraints you may find yourself under usually stem from the requirement to build a sensible, intuitive and smart UI, rather than from deficiencies in the programming tools.
I recommend you also look at the file that philmodjunk posted.
Let me get at it.