Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Duplicate Set with multiple Children

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Duplicate Set with multiple Children

    Gday all

    I have been using Peter Wayne script for duplicating a set with a parent and single child with never a problem. I now want to do duplicate a set with multiple children. I have managed to duplicate the first child OK, but the 2nd child duplicates the correct amount of records although the data is the same in every record (image attached).

    I have pasted the script beneath and hopefully someone can point out where I am going wrong.

    Many thanks

    Paul


    dim hdr as p
    dim items as p
    dim old_parent as b29-12-2012 5-23-53 PM.jpg29-12-2012 5-23-53 PM.jpg
    dim old_items as b
    dim count_items as n
    dim i as n
    dim hdr1 as p
    dim items1 as p
    dim old_parent1 as b
    dim old_items1 as b
    dim count_items1 as n
    dim i1 as n

    hdr=table.current(1)
    items=table.current(3)
    items1=table.current(6)
    count_items = count(d5qucon->d5quoteid,GRP->d4quote)
    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
    '
    count_items1 = count(d8quitm->d8quoteid,GRP->d4quote)
    if count_items1>0 then
    dim records1[count_items1] as b
    i1=0
    items1.fetch_first()
    while i1<count_items1
    i1=i1+1
    records1[i]=items1.record_data_get()
    items1.fetch_next()
    end while
    end if 'count_items1>0
    '
    old_parent=hdr.record_data_get()
    hdr.enter_begin()
    hdr.record_data_set(old_parent)
    hdr.d4quotdate=date()
    hdr.enter_end(.t.)
    if count_items>0 then
    for i=1 to count_items
    items.enter_begin()
    d5qucon.d5quconid=items.recno()+1
    items.record_data_set(records[i])
    d5qucon.d5quoteid=hdr.d4quoteid
    items.enter_end(.t.)
    next
    end if
    '
    if count_items1>0 then
    for i1=1 to count_items1
    items1.enter_begin()
    d8quitm.d8quitemid=items1.recno()+1
    items1.record_data_set(records1[i])
    d8quitm.d8quoteid=hdr.d4quoteid
    items1.enter_end(.t.)
    next
    end if
    '
    parent.resynch()

    #2
    Re: Duplicate Set with multiple Children

    Paul
    best post a sample with data.
    your code doesnt make clear what it is doing relative to the picture. No comments and spurious other value substitutions.
    Which part of the code relates? Comment your code and indent the loops to make it more readable.
    Example,On the face of it - this line
    Code:
    items.record_data_set(records[i])
    appears to be correct but something else may be wrong, in this code or in the set or the tables pointed to etc.
    Poking in the dark can result in many suggestions and replies back and forth.
    Ray

    Comment


      #3
      Re: Duplicate Set with multiple Children

      Hi Ray
      I have attached a screen shot direct from A5. The set has five child tables attached and I want to duplicate all associated records from the set when the copy button is pressed. Eventually, I will copy all tables but for testing purposes I am only copying two child table records. When I setup the code for one child table only (as per Peter Wayne's example in xbasic), it works like a dream. I have tried both child tables that I am attempting to duplicate and they work great (although that is the original code and I have tried to adjust that code to work with multiple child tables).
      The code only refers to a couple of key fields for autonumbering etc and they are correct (both in spelling & function).

      I hope that makes sense :)

      Thanks
      29-12-2012 7-10-57 PM.jpg

      Comment


        #4
        Re: Duplicate Set with multiple Children

        You have sent the same code again, just in a picture form
        with the same explanation of what you want to do but still no indication of - for example what table 1 or 3 or 5 d5qucon-> refers to AND no data to test against.
        All things being correct that you haven't provided, there is nothing apparently wrong with the code.
        Last edited by Ray in Capetown; 12-29-2012, 05:50 AM. Reason: And no data

        Comment


          #5
          Re: Duplicate Set with multiple Children

          Paul, sample data would help us help you.

          Is the set comprised of a parent and two children, or a parent, child and grandchild?

          Is there an autoincrement field rule in place in any of the tables? If so, which tables, and what's the autoinc field name in each?

          -- tom

          Comment


            #6
            Re: Duplicate Set with multiple Children

            Hi Tom

            The set is comprised of a parent and five children (one of the tables is not shown). Tables - Parent: d4quote, Child 1: d5qucon, Child 2: d6qucon, Child 3: d7quexc, Child 4: d8quitm, Child 5(not shown): d9setup. Autoincrement are in all tables (in the image, they are the fields that are highlighted).
            Please let me know if you need more info.

            Many thanks
            Paul29-12-2012 12-07-05 PM.jpg

            Comment


              #7
              Re: Duplicate Set with multiple Children

              Sorry, didnt update the image with the table/set layout :(29-12-2012 12-07-05 PM.jpg

              Comment


                #8
                Re: Duplicate Set with multiple Children

                Paul do you know how do send sample data?
                It will come with the form, data and any code.
                We can then test and advise accurately.
                Images dont say it all and without data would we like to type in rows and rows of what we think your tables and rules contain? Likely not.

                Comment


                  #9
                  Re: Duplicate Set with multiple Children

                  Hi Tom & Ray

                  noted and many thanks. Attached is the zip file. I will send you both a message.

                  Many thanks

                  Paul
                  Attached Files

                  Comment


                    #10
                    Re: Duplicate Set with multiple Children

                    Here's an example for you using a three table set.

                    -- tom

                    Comment


                      #11
                      Re: Duplicate Set with multiple Children

                      Hi Tom

                      your a champ !!, works like an absolute dream with the four children tables.

                      Thanks

                      Paul

                      Comment


                        #12
                        Re: Duplicate Set with multiple Children

                        Toms method is textbook - however the same attention to detail is required.
                        Your mistake here could occur again see in red
                        stick with the the same loop counter token if possible to avoid it. array [i] was the last read into a blob

                        Code:
                        if count_items1>0 then
                          for[COLOR="#FF0000"][B] i1[/B][/COLOR]=1 to count_items1
                        	items1.enter_begin()
                        	d8quitm.d8quitemid=items1.recno()+1
                        	items1.record_data_set(records1[COLOR="#FF0000"][i])[/COLOR]
                        	d8quitm.d8quoteid=hdr.d4quoteid
                        	items1.enter_end(.t.)
                          next
                        end if

                        Comment


                          #13
                          Re: Duplicate Set with multiple Children

                          Hi Ray

                          thanks for that. I will give it a go as I am trying to avoid any future mistakes where possible.

                          CHeers

                          Paul

                          Comment


                            #14
                            Re: Duplicate Set with multiple Children

                            Ray, I think using the same variable as a loop counter might be a bit dangerous unless each "loop block" of code is in its own Function ... End Function block. Remember, scripts will run asynchronously. When your code uses a loop to read from or write to the disk, Alpha Five will not wait for the loop to end before resuming its march through the script. Instead it will multi-task. The loop will keep running and the code after the loop will be executed while the loop is running. I'm worried that my example will fall over if the number of child records is large. Fortunately, Paul hasn't bumped into that yet... However, using the same variable as loop counter in each of a series of loop blocks invites trouble.

                            Comment


                              #15
                              Re: Duplicate Set with multiple Children

                              Advice taken Tom.
                              I'm thinking single-thread-mindedly.
                              I use pasting dup code for repeats to avoid that counter error, and I havent bumped into that problem, yet.
                              So you clearly think it possible that setting a counter to zero beyond the loop could affect the loop? That it may still be running.
                              If so thats scary, I always think linearly (procedurally) when coding.

                              Comment

                              Working...
                              X