Script Block - link records based on conditions

Hi everyone!

I have a particular situation where I’m trying to link several records from a view in one table to a specific view in another. I did some research from pre-existing articles–mainly this one–but I have a couple wrinkles for my script and don’t have the knowledge to make it happen:

I work for a non-profit where volunteers go online to write encouraging notes to authors who have sent digital stories to us. In this example base, you’ll see that I have one table for the digital stories, one table for the volunteer events, and one for the companies we work with.

Here are the complications: 1) I don’t want to “pack” any stories that were assigned to the same company from a previous event. 2) I want to assign a certain # of stories to the event based on number of attendees. So the script would count the number of attendees, multiply that by, say, 5, and assign that number of stories to the “assigned” field.

So in the “Volunteer events” tab, in the “Upcoming Events” view, I have an upcoming event with Company A:

The script would search for 5*{Expected Volunteers} stories from the stories tab, but would only link records that haven’t yet been assigned to a Company A event (without overwriting the linked record info that’s already there!)

Let me know what other info I can give, and thanks for the help! JavaScript is not my thing.