Alpha Video Training
Results 1 to 13 of 13

Thread: Update child records

  1. #1
    Member
    Real Name
    Mary Nickerson
    Join Date
    Aug 2000
    Location
    Waukesha, WI
    Posts
    33

    Default Update child records

    I have an order system that was created in Alpha 5 version4. I have the below coding on the 'on depart' button of the ship date field in an order entry screen. I am trying to update the child record's status field. The problem is that it only does the read and update of the first record and does not read any of the other child records. Can any one see what I am doing wrong and why this worked OK with previous versions of Alpha?
    Thanks - here is the code:

    tbl=table.current()
    if cdate(tbl.ship_date)"""".and.tbl.order_status="ENTERED"
    tbl.order_status="SHIPPED"
    parent.commit()
    lines=table.get("order_lines")
    lines.fetch_first()
    while .not. lines.fetch_eof()

    lines.change_begin()
    if lines.line_status ="ENTERED"
    lines.line_status = "SHIPPED"
    end if
    lines.change_end()
    lines.fetch_next()
    end while
    sys_send_keys("{F5}")
    end if

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

    Default RE: Update child records

    Mary,

    Shouldn't

    lines.change_end()

    be

    lines.change_end(.t.)

    ???

    -- t

  3. #3
    Member
    Real Name
    Mary Nickerson
    Join Date
    Aug 2000
    Location
    Waukesha, WI
    Posts
    33

    Default RE: Update child records

    You are right Tom. I put that in but it still only updates the first record. I tried the system in Alpha 5 V5 and it works perfectly. This seems so simple!

  4. #4
    Member
    Real Name
    Mary Nickerson
    Join Date
    Aug 2000
    Location
    Waukesha, WI
    Posts
    33

    Default RE: Update child records

    If I do not do the change begin and change end it does scroll through all the child records. It only stops when I have the change code in there. Hope this helps for anyone trying to give me an answer.

  5. #5
    "Certified" Alphaholic
    Real Name
    Finian Lennon
    Join Date
    Apr 2000
    Location
    Atlanta, GA
    Posts
    1,805

    Default RE: Update child records

    Just guessing here Mary but instead of:
    ===================
    lines.change_begin()
    if lines.line_status ="ENTERED"
    lines.line_status = "SHIPPED"
    end if
    lines.change_end()
    lines.fetch_next()
    ====================
    try

    ====================
    if lines.line_status ="ENTERED" then
    lines.change_begin()
    lines.line_status = "SHIPPED"
    lines.change_end(.T.)
    end if
    lines.fetch_next()
    ====================

    I don't know if the "then" will help or the reordering but it's worth a try.

    Finian

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

    Default RE: Update child records

    Mary,

    My personal preference would be to substitute

    lines = table.current(2) 'assumes child table is in slot 2

    for

    lines=table.get("order_lines")

    in order to get a valid pointer to the child table.

    -- tom

  7. #7
    Member
    Real Name
    Mary Nickerson
    Join Date
    Aug 2000
    Location
    Waukesha, WI
    Posts
    33

    Default RE: Update child records

    I tried your suggestion Finian and had the same results. Thanks for trying to help.

  8. #8
    Member
    Real Name
    Mary Nickerson
    Join Date
    Aug 2000
    Location
    Waukesha, WI
    Posts
    33

    Default RE: Update child records

    Tom:
    DId your table.current(2) with same results. I am thinking of moving the data out of my order lines table and trying this with new records. Maybe something is corrupted in the table. Of course everything is the same when I try it in version 5, but maybe version 6 is less forgiving.

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

    Default RE: Update child records

    Mary,

    OnDepart event will fire each time focus leaves the field, whether the primary table is in enter, view, or change mode. I'd probably put something like this in the OnChange for the field, or, even better, in the OnSave for the form. In pseudo code for the OnSave.

    And, if you haven't used debug(1) to see where the script is failing now would be a good time.

    -- tom

  10. #10
    Member
    Real Name
    Mary Nickerson
    Join Date
    Aug 2000
    Location
    Waukesha, WI
    Posts
    33

    Default RE: Update child records

    Thanks Tom and Finian. I found out the problem. The Order set was somehow bad (I guess). I got this from my client and who knows what happened on his system. I recreated the order line table and copied in the records. I receated a new Order set and everything works fine. It is amazing how version 5 did not have a problem with it and version 6 did. I am sure I will never know why, but it does boether me how somethings work Ok in version 5 and not in version 6. Thansk again.

  11. #11
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default RE: Update child records

    Mary:
    I beleieve there is a simple solution to your question and a bit of a complicated explantation, but instead of table.get() use table.open(), if it works, I will explain my theory, if it doesn't then my theory is flawed and not worth discussing! Hope it works.
    Gabe

  12. #12
    Member
    Real Name
    Mary Nickerson
    Join Date
    Aug 2000
    Location
    Waukesha, WI
    Posts
    33

    Default RE: Update child records

    Gabe - The files were fixed but I decided to do your table.open() and see what happens. It does work with table.open() and table.get() works also. Can you tell why 'open' is better than 'get'? I use table.get() alot so if I should be using table.open() instead, that will make my frustation with this bad set I had worth all the tearing of my hair out today.

  13. #13
    "Certified" Alphaholic G Gabriel's Avatar
    Real Name
    G. Gabriel
    Join Date
    Oct 2004
    Posts
    7,204

    Default RE: Update child records

    Mary:
    Before you go bald, here is my theory:
    In your xbasic, you used "IF"
    This creates a "query on the fly"
    In a5v6, alpha saves tose querries
    when you used table.get(), it opens the same table but it shows it according to the last index or filter which will not reveal all the records.
    On the other hand, table.open() will open a second instance of the table and will not be affected by that filter.
    This is just my theory, I do not know how valid it is.
    Gabe

Similar Threads

  1. update a child table
    By dik_coleman in forum Alpha Five Version 6
    Replies: 10
    Last Post: 10-09-2004, 03:45 PM
  2. update child records
    By geoff m in forum Alpha Five Version 5
    Replies: 3
    Last Post: 02-22-2004, 11:54 AM
  3. Update To Parent From Child
    By Thomas Holt in forum Alpha Five Version 4
    Replies: 3
    Last Post: 06-26-2003, 08:11 AM
  4. Update fails to find any records to update
    By joshua brimdyr in forum Alpha Five Version 5
    Replies: 6
    Last Post: 03-11-2003, 04:47 AM
  5. UPDATE CHILD
    By Peter Lear in forum Alpha Five Version 4
    Replies: 9
    Last Post: 11-06-2000, 03:27 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
  •