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

Need Script

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

    Need Script

    Hi,

    I know that this should be fairly simple, but when I'm on a Invoice line items, I need to run a script to do the following. The conditions in the field rules database ar not returning the values I need.

    Simply, I'll I want to do is have a script run on a field within a browse is do this.

    On the invoice browse field named Quanity, I need a check that does 5 things:

    1 - make sure that the Invoice Items "Quanity" is <= the Product "qty_authorized" field
    2 - additionally make sure that the Invoice Items "Quantity" is also <= Product "quantity_ in _stock" field

    3 - if both conditions are true, then subtract the Invoice "quantity from the Product "quantity_ in stock"
    4 - Add an entry to the invoice items that set's a Invoice "quantity_issued" field to the Invoice Quantity (for audit purposes)
    5 - in the product table , increment the product_usage by the Invoice "Quantity " for the product for tracking later.

    Has anyone written a script close to this ??

    Thanks,

    Ryland
    Last edited by [email protected]; 02-13-2009, 06:43 PM. Reason: error in detail

    #2
    Re: Need Script

    Hy Ryland,

    Under Operations, check out Posting. I think that you can probably accomplish everything with one Post operation.

    If you run into problems or questions, post back here and someone will jump in and help you.

    Bob Arbuthnot

    Comment


      #3
      Re: Need Script

      Thanks Bob, I'll give it a try this morning. Ryland

      Comment


        #4
        Re: Need Script

        Hi Bob"

        I tried an update and post operation on the invoice items, and for some reason, it is not taking the current row focus and updating just the "onsave" . It is updating all records

        I'm just not getting it....

        Any help with a sample script updating Product records from the Invoice item file will be appreciated.

        Ryland

        Comment


          #5
          Re: Need Script

          Hi Ryland,

          Have a look at Events->Events for the browse.

          The other thing to keep in mind is what will happen if you delete the row.
          Regards
          Keith Hubert
          Alpha Guild Member
          London.
          KHDB Management Systems
          Skype = keith.hubert


          For your day-to-day Needs, you Need an Alpha Database!

          Comment


            #6
            Re: Need Script

            Originally posted by [email protected] View Post
            Hi Bob"

            I tried an update and post operation on the invoice items, and for some reason, it is not taking the current row focus and updating just the "onsave" . It is updating all records

            I'm just not getting it....

            Any help with a sample script updating Product records from the Invoice item file will be appreciated.

            Ryland
            2 ideas

            1. Use action scripting to call the posting operation from an event for the invoice items and select only the current record.

            2. Have you tried a posting field rule instead of a posting operation? That will handle the question the Keith posed. ie when a record is deleted.
            Al Buchholz
            Bookwood Systems, LTD
            Weekly QReportBuilder Webinars Thursday 1 pm CST

            Occam's Razor - KISS
            Normalize till it hurts - De-normalize till it works.
            Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
            When we triage a problem it is much easier to read sample systems than to read a mind.
            "Make it as simple as possible, but not simpler."
            Albert Einstein

            http://www.iadn.com/images/media/iadn_member.png

            Comment


              #7
              Re: Need Script

              Hi Al,

              I have tried both possibilities:

              1 - in the product file, I crated a posting rule ior the invoice items.dbf linking the the table linking the source for product_id in both product and invoice items to add to a field in the product field "usage" to increment (add) from the number within the invoice items. Still no luck so far in getting that usage field to update.

              Of course I have a demo of Tuesday, and feel like an idiot in not getting this to work.

              Comment


                #8
                Re: Need Script

                Found a problem in the item lookup key, brinking up wrong productid number.......must be causing the problem...will keep ya'll posted.

                Ryland

                Comment


                  #9
                  Re: Need Script

                  You can easily accomplish this with a script in field rules for the lineitems table at the cansaverecord event and ondeleterecord event. Personally, I have never found posting to be reliable. Not sure why, but the amounts will occasionnaly get out of whack.
                  Cole Custom Programming - Terrell, Texas
                  972 524 8714
                  [email protected]

                  ____________________
                  "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

                  Comment


                    #10
                    Re: Need Script

                    Thanks, without opening the action script, do you happen to have an example I can use in order to use those events.

                    This is what I'm using on the cansaverecord event:
                    product.qty_in_Sto - invoice_items.Quantity

                    Ryland
                    Last edited by [email protected]; 02-15-2009, 10:11 PM.

                    Comment


                      #11
                      Re: Need Script

                      Don't take this personally but you've done it again! You're yet another person to prove my adage that it's time to worry when someone relatively new to databases (I make that assumption based on your 47 posts) says, "all I want to do is" or "this should be fairly simple."

                      It's amazing how many times new developers and customers think the hard things should be easy and the easy things should be hard. (I once had a customer apologize profusely before asking me to do something that he knew would be difficult - he wanted me to move a button from the left side of the form to the right side. Another customer thought a $6,000 estimate I gave him should have been more like $250 and certainly not over $500. My $6,000 quote was probably on the low side.)

                      I would say that this is actually one of the more complex things you will ever need to do. Not the most complex but far from "simple".

                      This isn't "an operation" - think of it as 5 separate operations. That way it will be much simpler.

                      Your items 1 and 2 sound like field rules - sorta. They aren't the kind of field rules that would ever need to be re-evaluated because the "qty authorized" and certainly the "quantity in stock" are likely to change from time to time and the only time that's critical is when the record is actually being entered. Therefore, I would script these checks in the CanWrite Field event of the table - not in the browse itself. Doing this in the browse itself would be difficult to say the least. Doing it as regular field rules (vs the CanWrite event) might mean that they would get re-evaluated and marked as errors if you needed to run the re-evaluate field rules command later on. (No guarantees on the "re-evaluate" concern but I'm pretty sure it's legitimate.)

                      If items 1 and 2 are part of the CanWrite events then you will never get to the OnSave event unless they are true. Therefore you don't need to worry about whether or not they are true. When the record is saved, some Post operations should handle items 3, 4, and 5.

                      My biggest concern with this would be the possibility of some unforseen issue when (a) changing the quantity later, (b) deleting a record, or (c) where you would need to override the limitations. I can easily imagine a situation where someone orders something that isn't in stock today but you are sure it will be available tomorrow. Then what do you do? Tell them to call again tomorrow and risk losing the order? Just food for thought.

                      Edit: I have to agree with Martin. I seldom use post operations myself.

                      In the OnSave Record event (not the CanSave Record event because (a) it wouldn't really be justification for not saving the current record and (b) you are changing something in another table) you will need a much more detailed script. Something along these lines (this is just off the top of my head):
                      Code:
                      DIM SHARED orig_qty as N
                      IF tc.quantity = orig_qty
                           END'
                      END
                      tc = table.current()
                      tp = table.open( "Product" )
                      tp.index_primary_put("Item_ID_")
                      tp.fetch_find( tc.item_idf )
                      IF tp.item_idf = tc.item_idf    [COLOR="Blue"]'JIC[/COLOR]
                           tp.change_begin()
                           tp.qty_in_sto = tp.qty_in_sto - (tc.quantity-orig_qty)
                           tp.change_end()
                      END IF
                      tp.close()
                      The "JIC" means "Just In Case" - you'll see it all over my code where something isn't really part of the basic logic but is done "just in case" something else goes wrong. In the above case, you might want to add a message in an ELSE section to tell the user that the item ID wasn't found and that it might be necessary to rebuild indexes.

                      There are a couple issues with what you tried. First, as pointed out above, you are changing something in another table so you would have to put it in Change mode. Second, something that simple might work in a set but putting it in the field rules of the table would be bad practice because it would cause errors if you ever tried to save that record while not linked to the other table. And, I don't care if you say, "but it will always be linked to that table" because there's no guarantee that that statement will always be true in the future. Someone is liable to come up with a report or form at some time that doesn't need that link and then you will have trouble.

                      Second Edit:

                      Oops, even that isn't good enough. It would work the first time around but won't work if you change the quantity or delete the record. (Remember when I said this was NOT simple!?) You really need to set a shared variable in the OnChange event then compare the current quantity to this variable in the OnSave event. I edited the code appropriately.

                      Another Oops - I noticed that I typed END' out of habit but I'll leave it there and explain why I do it. I put the single quote on the end so I can do a text search for END statements without finding every END IF, END WHILE, END FUNCTION, etc. This is actually a fairly common search because it's important to make sure all tables are closed before ENDing a script. Alpha says they try to close them if you forget but I've found that it's not good to rely on that - sometimes it doesn't happen. There are also other "cleanup" things that might need to be done like clearing the status bar and closing "Please Wait" messages.
                      Last edited by CALocklin; 02-16-2009, 12:39 AM.

                      Comment


                        #12
                        Re: Need Script

                        No offense taken.

                        I'm an old Progress and Cobol programmer (not GUI Based), so I'm not that well gifted at using all of the features, and just learning the Xbasic features. The trick is that I need to learn is when to use or not use pure scripting vs Xbasic.

                        Your suggestions make good sense. I suspected that it would not be that simple, buy was looking for a good jump start.

                        Thanks,

                        Ryland

                        Comment


                          #13
                          Re: Need Script

                          Cal, thanks, you saved me a lot of typing. I have been trying to find the time to respond to this over the last couple of days and now I just need to type 'ditto'. When I first read the initial post I thought to my self "wait till Cal reads that 'simple' comment" ;) A note on the code you posted. I think when you edited you left the line tc = table.current() in the wrong spot.


                          Ryland

                          Another issue I see in this process is the test for invoice line qty being less than the in stock value. Lets say you have a stock level of 6 for a product. The user enters a line for 5 of these items. 5 is less than 6 so the transaction proceeds. The stock level is now reduced to 1. The customer changes his mind and the user needs to change the qty to 4. If the canWrite event simply checks qty of 4 against the now current stock level of 1 this will fail even though we are actually going to increase the stock level.

                          I think you would need to use the difference in the before and after qty here as well (as Cal has already mentioned using it in the update part). Maybe in conjunction with the a_field_value system variable. If the new value is less then one can assume stock is being added back and just allow the transaction to proceed (adjusting the value appropriately in the OnSave event). If the new value is greater then check that the difference is less than the in stock value.

                          Also, since the test for allowing the qty value is being done at the field level and the update of the stock level is being done at the record level there could be a time lag in when this happens. It is possible for a second user to be processing the same product. Both could enter a qty and it would pass the test because their records have not yet updated the stock level. So it may be prudent to re-test the stock level in the update when the record is saved. And the event used would then need to be the canSave event.
                          Tim Kiebert
                          Eagle Creek Citrus
                          A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                          Comment


                            #14
                            Re: Need Script

                            Originally posted by Tim Kiebert View Post
                            A note on the code you posted. I think when you edited you left the line tc = table.current() in the wrong spot.
                            Yep. The tc = table.current() should have been the second line. I certainly needs to come before the IF statement!

                            Originally posted by Tim Kiebert View Post
                            Also, since the test for allowing the qty value is being done at the field level and the update of the stock level is being done at the record level there could be a time lag in when this happens. It is possible for a second user to be processing the same product. Both could enter a qty and it would pass the test because their records have not yet updated the stock level. So it may be prudent to re-test the stock level in the update when the record is saved. And the event used would then need to be the canSave event.
                            Good point! I hadn't thought of that issue. It just keeps gettin' easier and easier.

                            EDIT:

                            I just thought of something else. When you delete the record, the quantity doesn't change. So, if you want to be able to delete records, you may need to include something that checks the a_deleting_record variable (a system variable) and take appropriate action.
                            Last edited by CALocklin; 02-16-2009, 08:17 PM.

                            Comment


                              #15
                              Re: Need Script

                              Almost there thanks to all. Thought I would handle the records being cerified first :

                              On the Canwritefield under field Events this is my code:

                              'Date Created: 16-Feb-2009 07:28:55 PM
                              'Last Updated: 16-Feb-2009 07:28:55 PM
                              'Created By : Ryland
                              'Updated By : Ryland
                              DIM SHARED orig_qty as N
                              tc = table.current()
                              orig_qty = tc.quantity
                              IF tc.quantity = orig_qty
                              END if

                              tp = table.open( "Product" )
                              tp.index_primary_put("product_id")
                              tp.fetch_find("tc.product_id")
                              IF tc.quantity > tp.qty_auth

                              msgbox("quantity Issued Cannot Exceed Authorized Quantity Please Re-enter")


                              END IF
                              tp.close()
                              End

                              __________________________________________________

                              On the Records Events in the OnsaveRecord:

                              I'm getting into the fields, but the Product table is not being updated. Am I missing a on commit ??? Starting just using hard code values but the record does not change.

                              'Date Created: 16-Feb-2009 07:48:18 PM
                              'Last Updated: 16-Feb-2009 07:48:18 PM
                              'Created By : Ryland
                              'Updated By : Ryland
                              DIM SHARED orig_qty as N

                              tc = table.current()
                              orig_qty = tc.quantity


                              tp = table.open( "Product" )
                              tp.index_primary_put("product_id")
                              tp.fetch_find("product_id")

                              msgbox("in OnSaveRecord")
                              tp.change_begin()
                              tp.qty_in_sto = 100 'tp.qty_in_sto - (tc.quantity-orig_qty)
                              tp.usage = 200 ' tp.usage + tc.quantity
                              tp.change_end()

                              tp.close()
                              End


                              Figured if I get these two resolved, then the rest will come...

                              Thanks,

                              Ryland

                              Comment

                              Working...
                              X