Alpha DevCon 2018
Results 1 to 13 of 13

Thread: duplicate suddenly not working

  1. #1
    "Certified" Alphaholic Lance Gurd's Avatar
    Real Name
    Lance Gurd
    Join Date
    Jun 2005
    Location
    Southampton, UK
    Posts
    1,379

    Default duplicate suddenly not working

    this code based on the great Xbasic for everyone by Dr Peter has suddenly stopped working (it worked up until about a month ago - I dont need to use it that often)

    Code:
    dim hdr as p
    dim items as p
    dim old_parent as b
    dim count_items as n
    dim i as n
    hdr=table.current(1)
    items=table.current(2)
    count_items = count(purchase_items2->order_no,grp->purchase_header2)
    if count_items>0 then
    dim records[count_items] as b
    i=0
    items.fetch_first()
    while i<count_items
    i=i+1
    records[i]=items.record_data_get()
    items.fetch_next()
    end while
    end if 'count_items>0
    old_parent=hdr.record_data_get()
    hdr.enter_begin()
    ' note, in this table the inv_no is
    ' an autoincrement field
    ' a new inv_no is assigned by the field rule,
    ' which overrides
    ' the Xbasic record_data_set()
    hdr.record_data_set(old_parent)
    hdr.order_date=date()
    hdr.del_date=date()
    hdr.enter_end(.t.)
    if count_items>0 then
    for i=1 to count_items
    items.enter_begin(.t.)
    items.record_data_set(records[i])
    items.order_no =hdr.order_no
    items.enter_end(.t.)
    next
    end if ' count_items>0
    parent.resynch()
    end
    It now seems to copy the child records to the original header, not the newly entered header record. Anyone else confirm? I have tried it on two different databases with same effect.

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default Re: duplicate suddenly not working

    This would be easier for us to check if you supplied a working model with instructions for us to follow to find the event which triggers the code.

    Later...

    Is the link field in the parent table INV_NO or ORDER_NO ? Your script's comments suggest that INV_NO is autoinc ... is it the link field? Saying this differently: Is your script pulling the wrong field from the parent table when updating the ORDER_NO field in each new child table record?
    Last edited by Tom Cone Jr; 06-01-2007 at 08:48 AM.

  3. #3
    "Certified" Alphaholic Lance Gurd's Avatar
    Real Name
    Lance Gurd
    Join Date
    Jun 2005
    Location
    Southampton, UK
    Posts
    1,379

    Default Re: duplicate suddenly not working

    Hi Tom, thanks for looking.

    This code is an exact copy of Dr Peters copying records from a set.

    As you can probably tell the set is Purchase header -1:M - purchase items, linked on the order no field in both. The order no field in purchase header is auto inc. Basically I have used Peter's code and addapted to my field names, and added the date lines to change the copied header date to the current date, and that is it.

    This was re-designed in version 6 and has been used in version 7 and version 8 successfully until today, I don't understand!!

    attached is a small test database, run the rooms form to see the duplicate button.

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default Re: duplicate suddenly not working

    Ok, what confused me is the comment in your script referencing a different autoinc field...

    I'll take a look.

    -- tom

  5. #5
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default Re: duplicate suddenly not working

    Lance,

    In your example you made the wrong field autoinc. I made the link field in the parent table of your set autoinc assuming that's what you intended.

    I think you should report this as a bug. The record pointer in the parent table is not being moved after the new parent table record is entered. This should happen automatically, but it's not. Suggest you attach the example database with your bug report, but only after you fix the autoinc field problem mentioned previously.

    If you want to fix the script here's an easy work around:

    Code:
    'Date Created: 01-Jun-2007 03:12:57 PM
    'Last Updated: 01-Jun-2007 11:23:58 AM
    'Created By  : Lance
    'Updated By  : Tom
    dim hdr as p
    dim items as p
    dim old_parent as b
    dim count_items as n
    dim i as n
    hdr=table.current(1)
    items=table.current(2)
    count_items = count(room_areas->room_no,grp->rooms)
    
    if count_items>0 then
    dim records[count_items] as b
    i=0
    items.fetch_first()
    while i<count_items
    i=i+1
    records[i]=items.record_data_get()
    items.fetch_next()
    end while
    end if 'count_items>0
    old_parent=hdr.record_data_get()
    hdr.enter_begin()
    ' note, in this table the room_no is
    ' an autoincrement field
    ' a new room_no is assigned by the field rule,
    ' which overrides
    ' the Xbasic record_data_set()
    hdr.record_data_set(old_parent)
    hdr.enter_end(.t.)
    parentform.resynch()   'force record pointer in parent table to refresh
    ui_yield()  'force script to wait for user interface to catch up
    
    if count_items>0 then
    'for i=1 to count_items
    for j=1 to count_items   'use j instead of re-using i
    items.enter_begin(.t.)
    items.record_data_set(records[j])
    items.room_no =hdr.room_no
    items.enter_end(.t.)
    next
    end if ' count_items>0
    parent.resynch()
    end

  6. #6
    "Certified" Alphaholic Lance Gurd's Avatar
    Real Name
    Lance Gurd
    Join Date
    Jun 2005
    Location
    Southampton, UK
    Posts
    1,379

    Default Re: duplicate suddenly not working

    Thanks for that Stan, I will report the bug.

    In my example it is the area that needs to be the autoinc, not the link field, but the principle is the same.

  7. #7
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,832

    Default Re: duplicate suddenly not working

    Quote Originally Posted by Lance Gurd View Post
    Thanks for that Stan, I will report the bug.

    In my example it is the area that needs to be the autoinc, not the link field, but the principle is the same.
    You're welcome, I think, for whatever contibution you think I made. Tom deserves at least some of the credit.

  8. #8
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,298

    Default Re: duplicate suddenly not working

    No. In your example if you don't increment the room number, the room number entered into the new header table will match the original record's room number. You wind up with parent table records in your set that have duplicate link field values which is never recommended. Remember, in your form's set, the link field is room_no, not "area".

  9. #9
    "Certified" Alphaholic Lance Gurd's Avatar
    Real Name
    Lance Gurd
    Join Date
    Jun 2005
    Location
    Southampton, UK
    Posts
    1,379

    Default Re: duplicate suddenly not working

    Sorry, I did mean to thank Tom, and was talking to a customer named Stan at the time.

  10. #10
    Member preston2's Avatar
    Real Name
    Preston
    Join Date
    Nov 2011
    Posts
    763

    Default Re: duplicate suddenly not working

    Trying to figure this out and see if it can work for what I need.

    I have form which is built off a set.


    The reason for the set is so I do not have 816+ fields in one table.

    Looking at the examples here, since my set is all "One to One" would I need something like " count_items = count(matrix->matrix_id,grp->matrix) " ?

    Linking field is Matrix_ID

    Confused as hell.

    Alpha version 11.

  11. #11
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,832

    Default Re: duplicate suddenly not working

    see if it can work for what I need.
    And what would that be? Are you trying to get a record count of the matrix table?
    There can be only one.

  12. #12
    Member preston2's Avatar
    Real Name
    Preston
    Join Date
    Nov 2011
    Posts
    763

    Default Re: duplicate suddenly not working

    Stan, I originally posted this thread http://www.alphasoftware.com/alphafo...-child-records
    And you refered me to this tread.

    What I need to do is duplicate a record and all associated child records of the set to create a new record with all the same data as the first record in all the tables of the set save one unique field "Matrix_Name" and of course the Matrix_ID field which is auto-increment.

  13. #13
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,832

    Default Re: duplicate suddenly not working

    The count_utems in that script is used to loop through the child records associated with the current parent. For a one-to-one set count_items is always 1.
    There can be only one.

Similar Threads

  1. now() behaviour suddenly changes
    By gothic in forum Alpha Five Version 7
    Replies: 14
    Last Post: 06-16-2006, 03:27 PM
  2. v6 suddenly VERY slow.
    By CALocklin in forum Alpha Five Version 6
    Replies: 10
    Last Post: 10-30-2005, 06:30 PM
  3. Tables suddenly gone PLZ HELP
    By Gary Phillips in forum Alpha Five Version 6
    Replies: 8
    Last Post: 01-17-2005, 10:23 AM
  4. Weird duplicate files suddenly appear...
    By Newton Thomas in forum Alpha Five Version 5
    Replies: 13
    Last Post: 11-23-2004, 06:27 AM
  5. Printer Suddenly Won't Work!
    By Gerard Hoedema in forum Alpha Four Version 6 and Prior
    Replies: 2
    Last Post: 02-20-2004, 08:14 AM

Posting Permissions

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