AnsweredAssumed Answered

Copy a record to same table OR How do 'Go to object' and 'Go to Portal Row' really work?

Question asked by disabled_JustinClose on Nov 3, 2011
Latest reply on Nov 7, 2011 by philmodjunk

Title

Copy a record to same table OR How do 'Go to object' and 'Go to Portal Row' really work?

Post

I'm having trouble with getting "portal row select" and "Duplicate Record" to work.  My ultimate goal is to make a copy of a record in the same table (hence "Duplicate Record").  However, this is complicated by the fact that I want to also duplicate the line items associated with that one record.

I have 3 tables that are mostly of interest:  Users, Searches, LineItems.  Users is currently associated with Searches via User_ID (PK in Users, FK in Searches); the relationship is a cartesian product (X, not =).  LineItems is related to Searches via "Search_ID" (just a straight '=').

I am doing most of this work on a layout based on "Users".  I have a number of portals on this layout showing various bits of Searches.  I have one portal that shows the currently selected search (a global field in Searches records this selection).  Below that is another portal showing the line items for that selected search, so a portal showing "LineItems".

I can think of two ways to do this:  switch to a 'Searches'-based layout, do a find for the currently selected search, then duplicate that record (should only be one - it is a PK I'm searching on).  (How does duplicate really work, anyway?  How do you know what record it is working on?  And when it is done, I am assuming that the original record stays as the active/found record.)  The other option is to use my portals, which are already filtered to the items I want.

I have been trying to use my portals by using 'Go to Object' script steps and using the named objects.  (Yes, gave the objects unique names and using them correctly - did copy and paste of the text.)  So here are those steps:

          Go to Object [ Object Name: "SelectedSearchPortal"]
         Go to Portal Row [Select; First]
         Duplicate Record/Request

         #Update new row's info to reflect the current userID instead of the original's userID; and some other bookkeeping.
          Set Field...
          Set Field...
          Set Field...

So how would I select this newly created record if it doesn't automatically become the active record in the portal (which it probably shouldn't as the portal is filtered by the "Slctr_Search" global field)?  I need the new SearchID from it to adjust the copies of the line items I will make.  I suppose a new find (switching layouts if I do it from the portals page, but wouldn't have to if I went with a switch&find process from the start) using a MAX() function on the SearchID could work.  But what if someone else is making a new Search at that exact time, too?  :)  (Matching on USERID could help that.)

Back to the portal paradigm.  I switch to the line item portal to make copies of the line items, which should be showing the ones for the currently selected search (which is contradictory to my hope that the other portal might auto-update to the new one).

          Go to Object [ Object Name: "CriteriaLinePortal"]
          Go to Portal Row [Select; First]
          Loop
              Duplicate Record/Request
              Set Field...  (to match new SEARCHID)
              Go to Portal Row [Next; exit after last]
          end loop

In some ways it is probably a good thing that the portals don't update, because then I can use them to copy the existing stuff.  I just need to figure out how to best find and update the newly duplicated rows so I can properly update those records.

Thanks,
J

Outcomes