New call-to-action
Results 1 to 5 of 5

Thread: Duplicating a "Parent" record complete with "Children"

  1. #1
    Member
    Real Name
    Peter Galdes
    Join Date
    Dec 2005
    Posts
    10

    Default Duplicating a "Parent" record complete with "Children"

    Hi everyone,

    I'm a A5 newbie (but very experience DB programmer in other applications)..

    We purchased the products to help us switch some applications to a web based approach.. and so far it's been great!

    However I would appreciate some pointers towards solving what appears to be a simple query (but it's hurting my head!)

    A simplified illustration of the issue:

    We have 2 tables (Projects & Jobs) related to each other bya common "ProjectId".. I would like to place a button on a grid that will (with confirmation) copy an existing "Project" to a new "Project" complete with a duplicated set of "job" transactions. (I will also need to reset some of the attributes - i.e. job status = "Pending" - for all the new jobs as part of the process.)

    Anyone give me some hints/clues/sample code about where to start?

    I guess we need to add a "onClick" event to something on the form and then place some code that actually does the duplication of records - perhaps by using a temporary table?

    If this is pretty difficult to accomplish via the web interface then i would look at a function in the native interface - but web based would be so much better for us.

    Many thanks in advance!

  2. #2
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,646

    Default

    Here's a basic example. It's for an invoicing system, much like Alpha Sports. And while it's designed to be called from a button on a desktop form, it'll give you a start:


    Code:
    tHdr = table.get("invoice_hdr")
    Current_Record = tHdr.recno()
    HdrCopy = tHdr.record_data_get()
    tHdr.enter_begin()
    	tHdr.record_data_set(HdrCopy)
    tHdr.enter_end(.t.)
    Order_Key = tHdr.invoice_id
    tHdr.fetch_goto(Current_Record)
    
    tDet = table.get("invoice_items")
    tDet.fetch_first()
    tDet2 = table.open("invoice_items", file_rw_shared)
    while .not. tDet.fetch_eof()
    	tDet2.enter_begin()
    		tDet2.record_clone(tDet)
    	tDet2.enter_end(.t.)
    	tDet2.change_begin()
    		tDet2.Invoice_id = var->Order_key
    	tDet2.change_end(.t.)
    	tDet.fetch_next()
    end while
    -Steve


  3. #3
    Member
    Real Name
    Peter Galdes
    Join Date
    Dec 2005
    Posts
    10

    Default

    Thanks Steve!

    Im sure that will help alot - anyone got any advice as to wether that kind of approach will work on a web form (I'm guessing not due to the disconnect nature of them)

    Hope im wrong!

  4. #4
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,646

    Default

    The basics of this will work on a web form, which is why I provided it. But you'll have to do a bit more upfront to identify the starting table and record.
    -Steve


  5. #5
    Member
    Real Name
    Peter Galdes
    Join Date
    Dec 2005
    Posts
    10

    Default

    Excellent - Thanks!!

Similar Threads

  1. Set "Parent Record Only" programmaticall
    By Blake in forum Alpha Five Version 6
    Replies: 0
    Last Post: 06-11-2005, 03:11 PM
  2. Previous not "locked" to "Auto"
    By Richard Froncek in forum Alpha Five Version 5
    Replies: 2
    Last Post: 03-05-2003, 12:03 PM
  3. Deleting "children"
    By Martin in forum Alpha Five Version 4
    Replies: 8
    Last Post: 11-18-2002, 07:27 AM
  4. "Unable to add key to tag" and "hea
    By Noble Bell in forum Alpha Five Version 4
    Replies: 2
    Last Post: 05-12-2000, 08:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •