set variable in record using active portal row
I'm trying to use a button in a portal to set a variable in the active portal row, and another variable in a new (related) record in another table. The basic problem is that there are a number of payments due, and when one comes in I'd like to generate a disbursement sheet for that particular payment.
So I have a payment table and a disbursement table, and then a linking table in which I've defined "payment id" and "disbursement id" (for complicated reasons -- multiple recipients, etc., I'm treating this as a many to many relationship, although it's probably a one to many).
I have quite limited scripting skills -- I've attached an image of the script I have, which appears to be generating a new record in the disbursement table, and assigning "disbursement id" in the linking table, but does not assign any "payment id" (let alone the right one), in the linking table.
Thanks in advance for any help,