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

Updating all child records when parent field value changes.

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

    Updating all child records when parent field value changes.

    I tried to tackle this a few years back and got no where but there has to be away to do this.

    Basically lets say you have a Parent table with numeric field for a multiplier.

    The child records are shown on the form in a Browse Object.

    The child table has a calculated field that needs to use the multiplier from the parent.

    If the value in the Parent record changes I need it to also change all the child record calculation to reflect the change.

    Attached is a simple example of what I am trying to achieve. You will see two fields named "Each" and Each2". One tries to pull the multiplier from the parent table and the other tries to pull it from a field that is supposed to be filled with the value of the parent field.

    Confused yet?
    Attached Files

    #2
    Re: Updating all child records when parent field value changes.

    Remove the abt_items->MULT field rule, that's not going to work for later changes.
    You can use the OnChange event on the form to recalc all children at the time of event change. Or CanSave for when adding new children - depending on your app.
    Need suggested sample code for that?

    Comment


      #3
      Re: Updating all child records when parent field value changes.

      Originally posted by Ray in Capetown View Post
      Need suggested sample code for that?
      If you are asking if I need a sample code, then yes. I have looked all over wiki and cannot find anything that works yet.

      Comment


        #4
        Re: Updating all child records when parent field value changes.

        Preston,

        Are you under the impression that the calculated field rules for each and each2 are somehow different? There are no set field rules, only table field rules. If you examine both expressions in the Expression Builder you will note that the fields from the header table are not available. As you are building a table level field rule for the abt_items table

        ABT_ITEMS->COST*MULT
        ABT_ITEMS->COST*ABT_ITEMS->MULT
        COST*ABT_ITEMS->MULT
        COST*MULT

        are all effectively the same.
        There can be only one.

        Comment


          #5
          Re: Updating all child records when parent field value changes.

          I think I have figured it out. Scrap all the field rule calculations.

          Put a calculated field on the form to do the calculation of abt_items->cost*abt_header->Mult

          Place variable in the Browse object on the form and tie it to the calculated field.

          On the report, instead of using a Var in the Details just use a calculated field.
          Attached Files

          Comment


            #6
            Re: Updating all child records when parent field value changes.

            If you want it to calculated ONLY on a report then that is all there is to it, as simple as it is.
            This is what you asked
            If the value in the Parent record changes I need it to also change all the child record calculation to reflect the change.
            If you wish to change the records on the form when the parent value changes, without going into too much details, one reliable quite quick method
            Code:
            tbl = table.current(2)	' use the child table
            nr=tbl.query_create("","abt_id="+quote(tbl.ibt_id))	' set the query
            cend=nr.Records_Get()	'get the number of records (could use fetch_eof() if you dont require the number)
            then as usual, loop either while .not. fetch_eof() or For count = 1 to cend make the change in the table then resynch the form.
            As always, interested in any other view, this is the way I found works best.

            Comment


              #7
              Re: Updating all child records when parent field value changes.

              abt_id is numeric so you don't need the quote(). Getting a pointer to table.current(2) limits the records to those linked to the current parent so the query should not be necessary.

              That said, I wasn't able to make such a script operate correctly from a button on his form. Essentially the same script works in AlphaSports on the invoice form to change the value in the quantity field.

              Code:
              parentform.Commit()
              tbl = table.current(3)
              tbl.fetch_first()
              while .not. tbl.fetch_eof()
              	tbl.change_begin()
              	tbl.quantity = 3
              	tbl.change_end(.T.)
              	tbl.fetch_next()
              end while
              parentform.resynch()
              Didn't spend much time trying to find what's different in his set/form.
              There can be only one.

              Comment


                #8
                Re: Updating all child records when parent field value changes.

                neat and tidy.

                Comment


                  #9
                  Re: Updating all child records when parent field value changes.

                  At any rate I got things working the way I needed them too using the method I used in the Browse Test 2 sample.

                  That method does not really update the child table records and that is ok as a lot of fields I had in my app to hold data for calculations are no longer needed.

                  What it does do it display all the correct calculated values on the form and within the Browse Object that has the child table in it. And the calculations stick until you change some value that would affect the calculation values.

                  This is not a simple "price in a catalog" type app like the Alpha Sports Example is.

                  It takes a item cost and then modifies it 10 ways to Sunday that rely on total items in all the child records associated with the parent record. So as more Child Records (line Items) get added it changes the total item count which then changes every other calculation needed to get the sell price.

                  Anyway, it is working and pretty slick I might add.

                  Thanks for all the suggestions, they helped me out.

                  Comment


                    #10
                    Re: Updating all child records when parent field value changes.

                    Stan,
                    Shouldn't your script also work on a set based form with

                    tbl = table.get("tblname") ?

                    I am trying to use this script in the TitleClick event for the browse and can't seem to get it to work...

                    Edit:
                    nevermind - I tried it again and it worked. Apparently my script needed the parentform.resynch() instead I was trying to refresh the browse itself, which is always problematic for some reason.
                    Last edited by MoGrace; 03-21-2015, 02:01 PM.
                    Robin

                    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                    Comment


                      #11
                      Re: Updating all child records when parent field value changes.

                      You are correct. Table.get() should/does work equivalently. I just use the methods I learned first. Table.get() is probably better as it will not fail if the set is restructured for some reason.
                      There can be only one.

                      Comment

                      Working...
                      X