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.

duplicate a record and all the "child" data also?

Featured Replies

I am trying to figure out the best way to duplicate complex records... these have several portals in which related records are created, and when I duplicate, I want all that duplicated also. I have some ideas, but right now they all look pretty complicated. Anybody been there done that?

(What I'm really after here is a way to copy a record when user selects an "edit" button, then present either the original or the copy to the user for editing... end result, I hope, is a way to switch back to the original version if necessary or just see what it was... I have an audit log field that works OK but doesn't capture the child data)

  • Author

Yes it helps some... one of the posters in that thread mentioned a disconnected TOs approach. I post a question about that. I don't see there what he means, but it sounds like a more bullet proof route than a looping script.

If you look at the Relationships, you will notice that Current Invoice is a TO based on Invoice, but not linked to anything. This is what he means by a disconnected TO.

  • Author

There appears to be a missing attachment ... he refers to a FMP7 attachment but I don't see it anywhere. I'm new to this forum though... maybe I am not looking in the right place? All I can see is a link to a zip file, which is a couple of FP3 files and some scripting.

Look in the subject line and click on the word 'Attachment'. smile.gif

Hi JT,

There isn't a post on this page with an "Attachment" in it. Are you referring to the link in "See if [color:"blue"] this thread helps you." attached to the word [color:"red"] this in your first post.

HTH

Lee cool.gif

  • Author

Yes, I found the attachment in the linked thread. Thanks.

Yes, Lee, the linked thread is what we have been discussing.

Glad you found it, aadeanb! smile.gif

  • Author

Well, found it, studied it a while. I'm having trouble figuring out all the logic of the script. For whatever reason, in my own file, what I get is a new record with *only* the child data copied. Haven't figured out why this happens. But it looks like his sample does the same thing. However, since I don't really grasp the logic, I don't know how to amend it & get what I want... a copy of the current record AND it's child data.

Maybe after I take a break and look at it in a day or two it will click.... or maybe I'll do the much less elegant way that I think I can make work (lots of globals and setfields).

Well, if it helps, here's how I do it. You only need one additional relationship, from Parent::global to Child::ParentID. I denote this as Child|global below.


If [isEmpty(Get(ScriptParameter))]

  Allow User Abort [Off]

  Set Error Capture [On]

  Set Field [Parent::global; Parent::serial]

  Duplicate Record/Request

  Perform Script ["This Script"; Parameter: Parent::serial]

Else

  Commit Records/Requests [skip data entry validation; No dialog]

  If [not IsEmpty(Child|global::serial)]

    Go to Related Record [show only related records; From table: "Child|global"; Using layout: "Child" (Child)]

    Go to Record/Request/Page [Last]

    Loop

      Duplicate Record/Request

      Set Field [Child::ParentID; Get(ScriptParameter)]

      Omit Record

      Omit Record

      Exit Loop If [not Get(FoundCount)]

    End Loop

    Go to Layout ["Parent" (Parent)]

  End If

  Commit Records/Requests [skip data entry validation; No dialog]

  Halt Script

End If

  • Author

Thanks! Let me just try to get the logic a bit here before I try this.

In your solution, there is no disconnected TO... the parent table is related to match field in the child one by way of a global? Is this a straight equijoin?

Parent::Serial is just a field in the parent table that increments serially?

Parent is related to Child in two ways: one being the normal Parent::Serial to Child::parentSerial (change to whatever field names your portal uses), the other from a global in Parent to Child::parentSerial. The second is to make it easy to go to the original record's children (if there are any) once you are on the duplicated record. The script parameter is then used to overwrite the duplicated children records with the duplicated Parent::Serial.

I do not use disconnected TOs. I prefer to add a relationship than a TO that may appear to have no use in the relationships graph.

  • Author

Ah... I do believe I get it, now. Thanks a million.

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.