Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Creating a New Record In a Relationship

Featured Replies

Ok I have a odd question but can you create a record through a relationship without using portals?

Heres my problem... I have 1 portal that just shows a list of current records that are related... then I have 7 global fields that are filled in by user then a script does a check on it when you hit save and then copys the data to the portal.

This works 100% with no problem but I hate having to the portal show a new record line at the end everytime..

So what I did to fix this is to create 2 relationsships one for the portal(viewing no create) and one for saving.. The one for viewing doesnt show the empty line at all which is perfect..

The one for saving im haveing problems with.. It seems I can only create a new related record through another portal only (Using the go to portal row Last and then go to portal row next way).

Is there another way to create a new record without using portals through a relationship?

PS I tryied making a invisiable portal with 1 field and this worked perfect using the (Go to Field - Go to Last Row - Go To Next) but the problem is if the invisbale portal is clicked then it highlights...

  • Author

nm figured it out hehe

Dont know why this works but all I do is use a script to go to related record and then go a Globalfield to RelatedField and it works... ( I dont understand how its making a new record rather than writing over it but it works liek I want it to smile.gif )

I guess you could flip to the layout with the "allow creation of related records." But there is a limitation, in that it will fail when you run out of rows.

I seldom use "allow creation." I just call a script in the file where I want the new record. First I set the parent ID into a global.

You also need Constant=1 calculation fields in each file, and a constant relationship from the child to the parent (though in reality any relationship can get a global).

Scripts (psuedo):

Freeze Window

Check Globals

Set Field [ ParentID global, ParentID ]

Perform Script [External, "Child"]

[The script called in the child file]

New Record

Set Field [ ParentID, Parent_Constant::ParentID global ]

Set Field [ Field1, Parent_Constant::Field1 global ]

Set Field [ Field2, Parent_Constant::Field2 global ]

etc.

Exit Record

[A single step in the Parent file will return you.]

Exit Record

AvrioTech said:Ok I have a odd question but can you create a record through a relationship without using portals?

Yes.

1. Do NOT turn on "allow creation of related records" in the definition of the record-viewing portal.

2. Define a global field "gItemRecID".

3. Create a relation to the item file where gItemRecID = the auto-generated record ID field in the item file. Set this relation to allow creation of related records. Call the relation "Selected_Item".

4. Your new record script should do this:

set field [gRecordID, textToNum("")

exit record/request

#auto-create item record

set field [selected_Item::FirstName, gFirstName]

set field [selected_Item::LastName, gLastName]

set field [selected_Item::Address, gAddress]

etc.

#deselect item record

set field [gRecordID, textToNum("")

  • Author

Is there a difference between using a Global Field or Calculation as a relationship between the two files?

(basicaly in a large multiuser enviroment will it make a difference)

because right now im using a calculation field with a constant of 1 on both files and relating them that way and its working fine (single user but I havent tested it mutliuser)

  • Author

BruceR I tried what you said and got this response

The relationship "MakeNew" is not valid and must be corrected before this field can be modified.

Then you didn't follow the directions at step 3. Post a description of what you actually did.

A clever way to create related records that does not require a sub-script in the Child file is one that I learned last year from one of the gurus on FileMaker Caf

Your suggestion is just a more complicated and maintenance intensive version of the method I posted. If you don't want to use the actual auto-create record ID as the link field, then use a global on the left side and your temp field on the right. Put a unique value into the global like status(CurrentDate) & " " status(CurrentTime) & " " & random * 1000. Then you don't have to do the maintenance of cleaning out the temp key on the right side.

Also have a look at this thread as it is related and Helpful Harry attached a cool way, that also provides to create records from the "first" row of a portal.

You'd see why first is within quotes.

Hi Jim, I think you might have actually learned it from me here on this forum wink.gif

AvrioTech said:

Is there a difference between using a Global Field or Calculation as a relationship between the two files? (basicaly in a large multiuser enviroment will it make a difference)

because right now im using a calculation field with a constant of 1 on both files and relating them that way and its working fine (single user but I havent tested it mutliuser)

The performance is pretty much strictly dependent on the number of records in the relationship. The constant approach is the worst-perfomance approach. It passes ALL record IDs across the network. As your data set grows, this can lead to problems. Depends on record count and and your network.

Queue ...

Whaddayaknow! I vaguely recalled that it was either you or Bob W., but definitely remembered it was one of the gurus somewhere smile.gif And I'm still grateful to you for passing it on to me. Re-reading the original thread also reminded me of the multi-user issues involved, so thanks for that as well.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.