Hi Tony. There are (at least) a couple of ways to do it:
1. Have your script go to the table that the portal is based on (channels?) - in that context the script creates the new record and then navigates back to the original layout.
2. Make sure the relationship from the base table (amplifiers?) to the portal table has the checkbox "Allow creation of records in this table via this relationship" checked on the portal end (channels). Then the script can go to the last portal row (which represents a new record that will be created in the channels table) and set the foreign key field in the channels table with the AmpID to create the record.
Thanks, I did have the creation option set.. and it's working better now when first entering the portal, but once 1 channel is set and I click the button to add another channel it doesn't roll the serial value for the channel up one (ie create a new record or "portal line".
Is there a script command to "go to table" as you mentioned in #2? I'm not familer with one.
Feels like I'm so close to a solution!
(ps is there are way to copy from FM script editor and be able to paste into the forum here? - other than print to pdf and copy from there?)
What I have so far for the "Add New Amp Channel" button:
Go to Portal Row [ Select; Last ]
Set Field [ ChannelOutputInfo_AMPLIFIER::_fk_Ampifier; AmpInfo::__PK_Amplifier ]
Set Field [ ChannelOutputInfo_AMPLIFIER::_fk_Interrogation; $$Interrogation_pk ]
Hi Tony. Sorry my reply yesterday was brief. You are on the right track. You need to have a commit record step in your script. If the serial is not increasing correctly check how you have that field set up in your Manage Database - it should be set up with an auto enter serial number option. I have attached a simple sample file.
Hope this helps. Chris
Amp and Channel.zip 67.1 K
So I already had it setup for Auto-serial.. I did not have unique option, so I added that. I have tried the commit record command previously and it didn't work, I added it back in and it still doesn't advance the portal window to a new channel.
Your file is what I have, the only difference I can see really is that yours is not in a portal, so it's got to be something to do with that I'm thinking.
I'm totally stumped, I've spent hours reading and trying on this one..
it still doesn't advance the portal window to a new channel.
What exactly do you mean by that? a portal "window"? I suspect that some confusion of terms has led to a misunderstanding of what effect you are trying to create.
Keep in mind that you have been given two different methods for doing this. If you are going to change layouts to create the new related record, you don't also have to have the "create" option enabled.
In my own personal design preferences, I try never to use Go to portal row as a way to create or change a related record, it's just too "brittle"--a feature easily broken in a future layout change. My preference is, as described already, to change layouts to a layout based on the portal's table, create the record there--being sure to link it back to the parent record on the original layout and then return to the original layout. Either that or use a separate relationship with "create" enabled that allows me to have the script create the new record without changing layouts nor by using go to portal row.
What exactly do you mean by that? a portal "window"?
The items in the layout (see first post) are inside a portal in the tab selected. So they are in the Portal (drop the window term).
I'm trying to keep the look the same so the user knows they are adding channels for the amplifier they are working with and can go to the amp notes tab if need be and come back to the add channel tab.
Can you be more specific?
Your view will change at least by the fact that you've added another record in your portal. Exactly how do you want that to change with the addition of another 'channel' in the portal?
I'm trying to understand the problem you are having - so I'll summarise what I think it is (if I'm wrong you'll have to try to describe it a bit better).
I've had a look at the picture you posted in the original post. It looks like your portal only displays 1 related record. If that is the case your portal will only ever show 1 related record as specified in the portal setup dialog (see screenshot) ie. in my example it is related record number 1. If you use the vertical scrolling then the button to create the new amp channel will leave you showing the new channel in the portal.
I use a method I call 'Create Records without leaving home' (I didn't invent it). It works by using a Global Field in the parent table to the primary key of the child table. I have a demo DB and instructions it here.
It does require an additional relationship but this relationship can also be use to isolate a related record by loading the child record ID into the global field.
btw: I virtually never have the Create Records option checked for a portal relationship.