Open Manage | Database | Relationships
Find the relationship that defines this portal and double click the relationship line.
In the dialog that pops up, select "allow creation of records via this relationship" for the portal's table. Now the last portal row is the "add record" row where adding data, such as with your insert file script step, automatically creates a new related record.
Such scripts that directly interact with a portal can be a bit fragile. Future changes to your layout design can break your script. Also, not everyone likes having that bottom "add record" row in their portal. Thus, you may want to use this script instead:
Set variable [$ID ; value: ParentTable::PrimaryKeyField ]
Go To Layout [//layout based on portal's table]
Insert File [
Set Field [RelatedTableName::ForeignKey]
Go To Layout [original layout]
I'm stumped. 1) I don't get the Set Variable step at all. I'm not bothered by the add record row at bottom, so I went back to trying to get the portal working to allow new portal rows and paste the new document into the new record. 2) I have identical portals, but get different results.
I am a financial planner/investment adviser. I want to store planning documents, trade documents, and misc documents in one handy place.
Initially I had one portal for all three document types, but quickly found a proliferation of portal rows as each insertion required a new row, with big gaps between entries under each category. So I went with three portals, one for each document type, so that I could get a nice, tight list of documents under each category (see image). I used one related file, and set up three relationships, one for each target field, but exactly the same otherwise.
One works (allows multiple docs), the other two don't (keeps replacing the existing document in row 1). In the two that don't work, I see the add record field (second row), which verifies that add record is enabled.
They are all set up exactly in parallel. I've checked the Define Relationship parameters, the Insert scripts, and the portal setups.
In the script step, Select is not enabled, so that doesn't explain why the existing record is being replaced.
This is probably going to be something dumb (on my part), but I just can't find what makes one work and the others not.
As a desperate attempt, I bagged the whole approach and actually created three related files, one for each target field. Surely that will work. I set up the relationships, and proceeded to insert documents successfully into the first portal. But (maddeningly) the other two portals behave exactly as before -- each new insertion attempt replaces the previous content.
Now the first portal, which worked, doesn't, and the second portal has duplicate content (two portal rows for one related record). Something is obviously wrong. But it's not that complicated. Any ideas?
If there is a solution in Set Variable, I need more help with that. Don't get that one at all.
The method I described with the "allow creation..." option would not use any script at all. You would click the container field in your portal and choose "insert file " from the Insert menu.
Using a script with multiple portals, you have to correctly put the focus on the desired portal before steps like Go To Portal Row [last] will successfully interact with the correct portal. That's why this works only with the first portal. I strongly recommend the original option I suggested:
Save current ID value in a variable, switch layouts, create a new record, insert the file and then copy the value from the variable into the appropriate match field of the new record.
But if you want your script to interact directly with the portals, then do this:
Enter layout mode.
Select each portal in turn and enter a unique object name into the Name box found at the top of the inspector's position tab.
Then, make sure that your scripts use this pair of instructions for each of the portals:
Go to Object ["ObjectNameOfPortalGoesHere"]
Go To Portal Row [last]
Brilliant. Thank you!
The reason I am using a script is that I have a fairly deep file (library) management system on my HD. I created a calculation field that provides me the specific folder location for each client. The script includes a Copy step (copies folder location), and when I get the Insert File dialog box I just press Control_V, Enter, and I'm in the client's folder. Huge time-saver.
Everything seems to be working, with the Go to Object refinement. Awesome help. Thanks again!