Need context for your relationships. Which of the above is specified for your layout? Which for your portal of values? Which for the portal into which you will be creating new portal records?
And in the relationship between the layout's table occurrence and the portal's (where you want to add new records), is "allow creation of records via this relationship" enabled for the portal table?
You might find the slightly different approach for doing this--along with its detailed documentation explaining how things were set up and how they work found in "Adventures in FileMaking - Enhanced Value Selection" easier to implement in your solution.
In addition to a search portal where you can click to select an item, there is one popover in this example where you can enter a quantity in a field in the popover's portal that then creates a record (with that qty) in the layout's portal--and with little scripting to do it--just enough scripting to update the portal to show the new data.
I have created a portal in Commentary Detail. This portal holds the name, citation, court and case id field for cases which are referred to in the commentary. That portal Is based on the Commentary Detail | Cases Considered | Cases Referred to table occurrence.
I have a popover on Commentary Detail to add case referred to. In the popover is a slide panel with 2 panels. The first contains a portal based on the Commentary | All Case | Popover table occurrence and contains the case name, citation, court and case id. The second panel is a "new case" panel and comprises of fields from the Commentary Detail | New Case | Popover table occurrence.
I can add cases in the "new case" panel but they appear in the third row of the portal in Commentary Detail. If I create a new case and then go and try and add another case by the portal in the popover it keeps replicating the same case (ie the one I just created) so I end up with a portal with the one case details numerous times. If I try and add a case to the portal on Commentary Detail without first adding a new case in the popover slide control then it doesn't add the new case to the portal.
I would be grateful for any help. In the meantime I am going to look at the Adventures in Filemaking File. Thanks.
I'm disappointed to see that this starter solution is still absolutely devoid of any comments or other documentation to tell you how it works. It makes "reverse engineering" its design very time consuming and irritating. If you don't have have every detail in place in your attempt to replicate this technique, it won't work.
This is why I recommended an alternative example--which also has a popover example for both creating new records and selecting existing record to put into a portal, but which into which I have invested a great deal of time and effort into documenting how the set up was created and how it works.
The first thing that you need to check is to make sure that the correct values are being passed as script parameters to the script that you've posted here. Much of the work is completed in those script parameters so if they aren't passing the correct value to your portal, the scripts won't work.
To confirm, you layout specifies Commentary Detail and the portal into which you want to create new records refers to Commentary Detail | Cases Considered | Cases Referred To. Your popover portal refers to: Commentary Detail | All Case | Popover and the fields on your "new case" panel of the slide control are from Commentary Detail | New Case | Popover. Also, all three blue table occurrences share the same data source table presumably.
I can add cases in the "new case" panel but they appear in the third row of the portal in Commentary Detail.
That would indicate that you already have two related records in Commentary Detail | Cases Considered | Cases Referred To at the time your script adds a new, third related record to that table. The fields in those records, except for CommentaryDetailIDfk may be empty, but the records are there. You might try copying the value of __CommentaryDetailpk to the clip board, switching to a table view layout based on Commentary Detail | Cases Considered | Cases Referred To, enter find mode and paste the ID value into _CommentaryDetialfk before performing the find.
If I create a new case and then go and try and add another case by the portal in the popover it keeps replicating the same case (ie the one I just created)
First thing that I'd double check are those script parameter expressions. Doesn't sound like they are being set to the correct values. Next thing to do depends on whether you have FileMaker Advanced or just FileMaker Pro. If you have Advanced, try running this script in the debugger while using the data viewer to watch the values of your fields. You can use Get ( ScriptParameter ) as a watch expression to check and see if the expected data is being passed as a script parameter. If you do not have Advanced, you can try inserting some show custom dialog steps into different parts of the script with selected fields, variables and expressions such as Get ( ScriptParameter ) to pause the script and display current values as a way to monitor the script and spot where/how it is failing.
Thanks Phil. I agree that it would be helpful for the starter solutions to provide comments or documents. I think it would save a lot of angst for beginners. It's hard to fix things when you don't have a working understanding of how they came to be in the first place. I'm working through your enhanced value selection database now and I am starting to be able to pull it together. I expect that I'll use your examples over the starter solution. I'll let you know how I go with it.
I worked through the AIF file and made the amendments to my database and it's working beautifully! One small thing I can't seem to work though, I want the popover to close when the case is selected. I've added in a script step (see below) to close the popover but it doesn't do anything. Any suggestions?
Thanks so much for the AIF file, I was able to understand how it was created and it made it so much easier to be able to see where I needed to tweak things in my layout/field selection to make it all work.
Do either of the go to object steps shown after the Close Popover step refer to the popover panel or some object inside the popover panel?
That would explain what you are describing here. Especially as I seem to recall that the AIF examples use a go to object to keep the popover open. (Changing layouts will close the popover anyway so you shouldn't need to specifically close the popover if the script is changing layouts.)
All fixed. It was the optional script parameter that I had on the button setup that was mucking things up. I've removed it and it works perfectly now!