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.

Create a child record from a script ?

Featured Replies

  • Newbies

I am new to the concept of having several Tables in one Database.

Previously, when I had to create a record in a (child) related database, I transferred the data using globals, then called a script in the related database, which added the record.

Now, this should be easier with multiple Tables in one database I thought. Just call "New record", specifying the Database and insert the data.

However, "New record" will create a record in the parent database. You cannot specify the target table - or I simply did not find this function.

Well, I can jump to a layout where only the child database is listed, or as an alternative, can jump in a layout, where a portal is visible, then jump to the last record if the portal and then add the data (add some code to freeze the window, stop user-interaction etc. etc. )

But this looks for me more like a workaround then a good solution.

Could anyone with experience with FM7 give me a tip to do this a better way ?

Thanks.

Hi, Phil, and welcome to the forums!

If your relationship is set to allow creation of related records on the right-hand side, then simply setting a value for a field in the related table (other than the key field) should create a new record in the child table.

HTH,

Jerry

  • Author
  • Newbies

Thanks for you answer QuinTech,

That works, but only for one record. If there are already records present in the table, no new record will be created, instead, the current record will be overwritten by the new value.

I should have described the problem more exact:

I have a text field where you can paste some lines of text. A script then parses the text in that field and filters out unneeded characters and blank lines. The remaining lines should go into the child table. One record per line.

I would like to omit switching to a layout where the child table is visible.

I would like to omit switching to a layout where the child table is visible.

Hmmm... i don't know if that is possible. I could be wrong, though. I was about to recommend that you insert script steps such as:

Go to Field (Field in Portal)

Go to Portal Row (Last Row)

And then create your new record. This would, indeed, create a new child record without overwriting what you've already got, but given the last line in your post, i suspect you've already tried this and don't like it so much.

Maybe you could add a tiny, tiny portal (with fields in 1-point font) to the layout you want people to see, and then hide it somewhere? That way, you could have that last-portal-row functionality without having to switch layouts. If you cover the portal up with a button or a picture, it shouldn't be noticeable.

J

  • Author
  • Newbies

Right,

I am already doing this - If there is no other way, then ok. I just thought, there could be an easier way. From my experience, if you have to do operations like this with a larger numbers of records, performance will suffer, but I have just begun to try out FM7, maybe it behaves better then older versions, also the Computing Power of a G5 is much better compared to a G3 with OS9 and FM4/5, so you dont notice the slowdown.

btw. to delete all related records my workaround is:


Loop

   Go to Field [child::somefield0]

   exitLoop If [Count (child::somefield0,child::somefield1,child::somefields2) = 0]

   Delete Portal Row[No dialog]

End Loop

I suspect, this also is the way do do it.

Thanks again for your replies !

Sorry, i can't think of any other way. Maybe someone else knows...

As for your related-record deletion, a quicker way might be:

Duplicate the parent record

Change the key field in the original record

Delete the duplicate (making sure the option "Delete related records" is selected in the relationship). This will delete those related records.

Back in the original record, change the key field back to what it was originally.

J

Of course it's possible - see attached.

Creator.fp7.zip

comment, all i'm seeing is the creation of the first related record. What am i missing?

Huh? It creates as many related records as there are lines in Parent::Data.

  • Author
  • Newbies

Works for me too - Nice trick!

By first using a non existent key you create a child record. Then change the key to the matching value of the parent.

Then repeat until done.

You got it. One caveat though: in a multi-user situation, there's a potential for conflict if two users are calling the script simultaneously. I believe this can be solved by changing the global key calc to something that is user-specific, or Random.

I see. I was trying to enter a value, then click Generate, then enter another value, then click Generate again. Didn't realize you had to enter a multi-line entry. I should've paid attention to the script!

J

  • 6 months later...
  • Newbies

Just a quick add-on to this one.

Can anyone add any light on to how to do this from one portal to another, rather than one field to another portal?

You may be missing the point here: "this" is NOT using a portal. Just be anywhere where you can (a) create records in the target table via a relationship (in version 7 that could be one or more tables away), and (: have acces to the data you need to pass to the new record - whether it is in the current record, or a related one.

  • 3 months later...

I'm new to this Table Occurance stuff. Could you tell me how Parent::gCreator can have a relationship to NewChild::ParentID when gCreator =.5?

I geuss I just don't get his concept...

Well, it does have a relationship - it just doesn't have any related records. Until you set a field of the 'non-existing' record - then a new record is created, and it's ParentID has a value 0.5.

This is very similar to the last row in a portal. There's no record there, until you start typing into it. That creates a new record.

of course,I understand now.

Thank you

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

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.