Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

SetField vs Copy/Paste to establish link


This topic is 8248 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have two db's I want to link but need to do it in a somewhat unusual fashion. The relationship between DB A and DB B is called Link and the key field in DB A is Field X and in DB B is Field Y. I start in DB A and enter data in Field X. I click on a button that copies the contents in Field X, takes me to DB B, creates a new record and pastes the result in Field Y. This establishes the relationship Link between the respective records. This works but forces me to have both Fields X and Y in their respective layouts. SetField would be a better solution but it does not work because the record I just created isn't linked until the key Field Y is populated with the data necessary to establish the relationship Link.

You get a gold star if you can understand my description of the problem. You'll have my fullest gratitude if you can lead me to a solution. ;-)

Posted

One option is to use a portal. Be sure to define the Link relationship to Allow Creation of Related Records. Then use Go to Portal Row (last) and Set Field() functions to create the related records. The related key in DB B will be automatically filled in.

Posted

Peter,

Thanks for the information. It works just as I wanted. It took a while to implement - although the info you gave me worked from the start I was marrying it to another feature that I just couldn't get to work. After much time I realized it was exactly what I had done on a db about a year ago. Dug up the old script and now all is working well. Seems I forgot about the Go To Related Record script function blush.gif

As the saying goes, "Live and (re)learn."

Ed

Posted

I'm glad it's working for you, Ed!

As the saying goes, "Live and (re)learn."

I'm reminded of that myself from time to time. smile.gif

Posted

Just settled down to work on the db and discovered something I didn't realize before - the process described earlier in this thread only works to establish the first new related record in the second db. Additional records in the second db must be implemented via a different script, perhaps something like create a new record and set the linking field. This certainly makes sense but I'm just checking to be sure I didn't miss something or set up something wrong that is preventing the original script from creating a second record in the second db related to the original record in the master db.

Hmmm, I just hope somebody other than a Vulcan can understand what I'm trying to say!!!

Posted

The Go To Portal Row (Last) step should create a new related record, if the relationship is set up to Allow Creation of Related Records.

Posted

Peter,

Back to work - we've been caring for our 3 year old granddaughter while our son and daughter-in-law move. Not much database gets written in such a time - where do they got all that energy?!?!?!? tongue.gif

I'm still stuck with the issue that the above process only creates a new record if the related file does not include a related record. As soon as a related record exists the process merely goes to that record (or the last record if more than one exists). I have the two files related in both directions (from A to B and from B to A) using the same key field and I have both relationships set to allow the creation of new records. I'll keep on it until I figure it out - any clues will be appreciated.

TIA,

Ed

Posted

You need an layout with portal on it, even if you'll never access it directly.

You need it in script.

So

Go to Layout[ (with portal from rel that allows creation of related records)]

Go to Portal Row [last]

Set Field [any field from rel, any value]

//or if you don't want to set any other field in rel file

//Set Field [rel::rightKey, leftKey]

//where your rel is established as leftKey-->rightKey

Go Layout [original layou]

HTH

Dj

Posted

Grazie, Dj for your suggestions.

Unfortunately I still can't get the script to work. I did take an indirect suggestion from your comments and will use it from now on - I have been putting multiple portals on some layouts and set up a field named "Empty" for each file the portals link to. Then I would use a Go To Field command to "enter" the portal so I would be sure the correct portal was being addressed. I have revised all that and now put a single portal on an otherwise unused layout and use Go To Layout to address the necessary portal.

I've checked all relationships to be sure adding records is allowed. All key fields are properly matched - all are text and no calculated fields are used. The script works fine when it is inserting the first related record, but merely goes to the last existing related record when trying to add another related record.

The full script is as follows:

Go to Layout ("PortalA")

Go to Portal Row (Last)

Set Field ("FileB::FieldX", "FieldY")

.... [i have used both key and non-key fields for X and Y.]

Go to Layout ("Welcome")

..... [This is the layout the script starts in and the move here is only for aesthetics]

Go to Related Record (Show, "FileB")

Any suggestions will be greatly appreciated.

Ed DiTomas

Posted

I kind of divide schemes for creating new related records into two groups. If the user is adding information that consists of just a few entries, typing into the last portal row works just fine. For applications where the creation of related records is part of a larger procedure, I avoid using a portal completely. I find it is more reliable to create a "New Record" script in the related file and run it as an external script. I use globals in the primary file for any values that need to be passed. A constant relationship from the related file to the main file is used to access the global field and place their values into the new related record.

I'm really not too fond of the use of portals in scripting automated procedures.

-bd

Posted

Easy, you need to select "show vertical scroll bar" option for your portal. wink.gif

LiveOak, it's just as good as creating "New" script in related file and passing data thru const rel and globals.smirk.gif

Dj

This topic is 8248 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.