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 a record found in a set

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

    Duplicate a record found in a set

    In Quickbooks one is able to duplicate a parent and child record from a set by the click of a button (for example, making a duplicate invoice record that has client name and then line items for that cliend). I would like to do the same in Alpha and was wondering if it is possible, looking at a default browse record that lists both parent fields and children fields, to duplicate that entire record using an Action Script? Or will have have to do a two step process of duplicating the parent record and then duplicating the child record?

    When I am in the default browse for the set and go to the pulldown menu for Record, the duplicate record is greyed out.
    "Ollie, remember how dumb I used to be? Well, I'm much better now."

    Pete

    #2
    Re: Duplicate a record found in a set

    Pete, I don't think there's a single function that will copy the parent table record and all related children, and then enter them both automatically in new records in both tables.

    This is of course possible to do in Alpha Five, indeed Dr. Wayne describes it in detail in his earlier book "Application Programming With Alpha Five Version 5" (it may even be addressed in his new book, "Xbasic for Everyone 8", available in the store at Alpha's website. [Yes, it's in Ch. 35]

    IIRC a single script is developed that copies the parent table record to a blob, then creates an array of blobs for the linked children. Child table records are assigned to each element in the blob array, and then new records are created in the two tables, and blobs are assigned to each. It will run just fine from a single button push, just like Quickbooks!

    Comment


      #3
      Re: Duplicate a record found in a set

      Thanks, Tom. I have the book, so I will take a look. I am not familiar with blobs, other than those I sometimes find in my pool, so that will be interesting.
      "Ollie, remember how dumb I used to be? Well, I'm much better now."

      Pete

      Comment


        #4
        Re: Duplicate a record found in a set

        Pete

        I requested this function from Alpha, 3 or 4 years ago at one of the annual get togethers.

        In the meantime using action scripting & operations

        1. Copy parent & applicable child records to temporary files.
        ..e.g. Header to headert, detail1 to detail1t......

        2. Update temporary files to change the key.
        .. e.g. Order # +"01"

        3. Append temp to master files.

        never could get to run from 1 button, timing issue ?

        Run as three operations.

        John

        Comment


          #5
          Re: Duplicate a record found in a set

          John:
          Thanks. I found Peter Wayne's code and will try that as well. I was thinking about putting a request for a duplicate button on the wish list, as it seems like something that could be a plus. The reason for the duplicate invoice or actually in my case a duplicate estimate is that I would like to keep the old estimate and then add on changes to the original estimate and still have a copy of the old estimate as a comparison. As I stated originally, Quickbooks provides this, but I am sure there is some extensive coding behind the scenes there as well. Thanks for your input. I will try your suggestion as well.
          "Ollie, remember how dumb I used to be? Well, I'm much better now."

          Pete

          Comment


            #6
            Re: Duplicate a record found in a set

            Ok, I tried copying the code from Dr. Wayne's new Xbasic for Everyone, chap 35 of duplicating both the parent and child records. I can't save the code as I get an error message that says "mismatched end loop or if-block". I can just about follow the xbasic code, but for the life of me I don't understand the error message at all. I took out the "while" to "end while" code and there is no problem, so it must be in that particular loop where the code is not correct. Any suggestions would be appreciated...

            Code:
            dim hdr as p
            dim items as p
            dim old_parent as b
            dim old_child as b
            dim old_hdr_recno as n
            dim new_inv_no as c	
            
            hdr=table.current(1)
            items=table.current(2)
            second_items_pointer=table.open("inv_items",file_rw_shared)
            
            old_parent=hdr.record_data_get()
            old_hdr_recno=hdr.recno()
            hdr.enter_begin()
            	hdr.record_data_set(old_parent)
            	hdr.date=date()
            hdr.enter_end(.t.)
            new_inv_no=hdr.inv_no
            
            items.fetch_first()	
            while.not.items.fetch_eof()
            	old_child=items.record_data_get()
            	second_items_pointer.enter_begin()
            	second_items_pointer.record_data_set(old_child)
            	second_items_pointer.inv_no=new_inv_no
            	second_items_pointer.enter_end(.t.)
            	items.fetch_next()
            end while
            second_items_pointer.close()
            parent.resynch()
            "Ollie, remember how dumb I used to be? Well, I'm much better now."

            Pete

            Comment


              #7
              Re: Duplicate a record found in a set

              Pete, the line that seems odd to me is:

              Code:
              while.not.items.fetch_eof()
              I'd write it this way:

              Code:
              while .not. items.fetch_eof()
              Otherwise the code seems fine to me. Can't trouble shoot this for you without copies of the tables and set. It's possible a mismatched data type or field name is throwing things off, so double check that if adding the blank spaces doesn't get it for you.

              Comment


                #8
                Re: Duplicate a record found in a set

                Tom:
                Thanks so much for your help. I went back and used Peter's second example (as you had originally suggested, I think) and that worked . Now, duplicating works just like Quickbooks! I wish I could really understand xbasic, because this is very neat!
                At least I typed in the code correctly on my second try. Thanks also to Dr. Wayne's code...

                Thanks again.
                "Ollie, remember how dumb I used to be? Well, I'm much better now."

                Pete

                Comment


                  #9
                  Re: Duplicate a record found in a set

                  Pete, the key to understanding xbasic is to go slow. Study each line. Check the help file discussion. Don't try to grasp the next line until the first line has been studied and you understand it. If you have trouble finding the help file topic for a given command or statement post a message here and we'll point you in the right direction. Learning where things are found in the help system is part of learning xbasic. It's a big mistake to adopt someone else's code without understanding how it works. There may be limitations inherent in a given approach that wouldn't be apparent without study. It's your code. Understand how it works. You're responsible for it.

                  Comment


                    #10
                    Re: Duplicate a record found in a set

                    Pete,

                    i am trying to use this function and am using dr waynes second method. i am getting an error,

                    Code:
                    dim casefile as p
                    dim target as p
                    dim old_parent as b
                    dim count_items as n
                    dim i as n
                    casefile=table.current(1)
                    target=table.current(2)
                    count_items=count(casefile->caseref,GRP->casefile)
                    if count_items>0 then
                    dim records[count_items] as b
                    i=0
                    target.fetch_first()
                    [COLOR="Red"]ERROR: Argument is incorrect data type[/COLOR]
                    did you get this error and how did you solve it.

                    thanks

                    Comment


                      #11
                      Re: Duplicate a record found in a set

                      Richard:
                      This is the code that works for me. You will have to sort through the field names..I put in the message to test my count items. Let me know if this is helpful to you. I just tried it again and it works for me. I had 3 line items.

                      .
                      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(3)
                      count_items=count(invoice_items->invoice_Number,GRP->invoice_header)
                      if count_items>0 then
                      	ui_msg_box("help","Will this work")
                      	
                          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
                          	old_parent=hdr.record_data_get()
                          	hdr.enter_begin()
                          	hdr.record_data_set(old_parent)
                          hdr.enter_end(.t.)	
                          if count_items>0 then
                              for i=1 to count_items
                              		items.enter_begin()
                              		items.record_data_set(records[i])
                              		items.invoice_Number=hdr.Invoice_Number
                              		items.enter_end(.t.)
                      next        		
                          end if
                      parent.resynch()
                      end
                      
                      'Refresh data in current form at parent level.
                      'Can only resynch data in View mode, so save record first to be sure that layout is in View mode.
                      topparent.Commit()
                      topparent.Resynch()
                      topparent.Refresh_Layout()
                      'Refresh  'Browse2' in current form.
                      topparent:Browse2.refresh()
                      
                      'Go to first record in current form at Browse2 level.
                      topparent:Browse2.fetch_first()
                      "Ollie, remember how dumb I used to be? Well, I'm much better now."

                      Pete

                      Comment


                        #12
                        Re: Duplicate a record found in a set

                        more - dont know how, but its working now.

                        Comment


                          #13
                          Re: Duplicate a record found in a set

                          pete,

                          just seen your reply. i see you added some extra code at the end.

                          this will be useful.

                          thanks for the code

                          richard

                          Comment


                            #14
                            Re: Duplicate a record found in a set

                            Pete,

                            As Tom said,
                            It's your code. Understand how it works. You're responsible for it.
                            I am not crazy about using table.current(1) and table.current(3). First off, six months from now when you look at the code will you remember what file is current(1) and what file is current(3)? Second of all if you or another programmer changes the definition of the set, current(3) may be accessing the wrong file.

                            Much safer and more readable would be
                            Code:
                            hdr=table.get("header")
                            items=table.get("items")
                            The there are no questions at all on which files you are accessing.

                            Just my two cents worth. (OK less than that with today's economy)

                            Jeff
                            Jeff Ryder

                            Comment


                              #15
                              Re: Duplicate a record found in a set

                              Jeff:
                              Thank you for your insight. Tom is correct in that I should learn this coding business. I don't have a firm grasp of it and probably never will. It was suggested to me to look at Dr. Wayne's code and I did that, adjusting it slightly to work for me. Your suggestion certainly makes good sense and is a nice gift on a day when gifts are in short supply.
                              "Ollie, remember how dumb I used to be? Well, I'm much better now."

                              Pete

                              Comment

                              Working...
                              X