8 Replies Latest reply on Mar 16, 2010 12:38 PM by RickWhitelaw

    Script Help

    psbajohr

      Title

      Script Help

      Post

      Hello all,

       

      I have the following script, which I've been told the Copy/Paste Function works inadequately, and there is a better option....therefore I've come here.

       

      Here's my script:

       

      Go to Layout ["Available to Distribute" (Available to Distribute) ]

       

      Perform Find [Specified Find Requests : Find Records; Criteria: Available to Distribute : : Prepare for Issue?: "Yes" ]

      [Restore]

       

      Copy [ Available to Distribute : : Type of Equipment ]

      [Select]

       

      Go to Layout ["Issued Equipment Inventory" (Issued Equipment Distribution Table) ]

       

      New Record/Request

       

      Paste [ Issued Equipment Distribution Table : : Equipment Model ]

      [Select]

       

      Go to Layout ["Available to Distribute" (Available to Distribute) ]

       

      Perform Find [Specified Find Requests : Find Records; Criteria: Available to Distribute : : Prepare for Issue?: "Yes" ]

      [Restore]

       

      Copy [ Equipment Available to Distribute : : Serial Number ]

      [Select]

       

      Delete Record/Request

      [No Dialog]

       

      Go to Layout ["Issued Equipment Inventory" (Issued Equipment Distribution Table) ]

       

       Paste [ Issued Equipment Distribution Table : : Serial Number ]

      [Select]

       

      Go to Layout ["Issued Equipment Inventory" (Issued Equipment Distribution Table) ]

       

      Basically what I need to do with this script is move multiple items (which I have a field created and when I type the word yes, its found by the script).  As of now, this script works, but  if I write yes in 5 records, it is only copy and pasting the first record into my issued inventory.

       

      So the help I need is to make this script able to find multiple "yes" records and move the multiple records from my on hand table to the issued table.

       

      I am using FMP10, win xp.

       

      Thanks.

      Paul

        • 1. Re: Script Help
          RickWhitelaw

          You need a loop. 

          1. Go to Layout

          2. Perform your find

          3. Go to record/Request (first)

          4. Loop

          5. do all the stuff you need to do with this record

          6. Go to Record/Request (next;exit after last)

          7. end loop

          8. do whatever else you need to do.

           

          Above is a rough description of what you need to do, not exact syntax, but it should get you where you need to go. You should consider using Set Variable coupled with Set Field instead of copying and pasting. 

           

          RW

          • 2. Re: Script Help
            philmodjunk

            I think I've posted this before....

             

            I wouldn't create and delete records like this at all. There's a simpler, safer approach.

             

            Make one table with a status field that records something like "IN" or "Out".

             

            To check out an item change the field to Out. To check it in, do the opposite.

            To see a list of all items in stock, do a find for all records with "IN" in the status field.

            To see alist of all items checked out, do a find for all records with "Out" in the status field.

            • 3. Re: Script Help
              psbajohr

              Thank you for the quick reply.

               

              I tried inserting loop, however, it seemed to be almost infinite....am I missing something?

               

              Where should I put the loop in the script and where should I end it?

               

              Thanks PB

              • 4. Re: Script Help
                psbajohr

                Phil,

                 

                I absolutely need two separate inventories, you are correct when you said you answered this, however, at the time, I did not have a correct script to utilize, whereas now I do, I'm just asking what I need to have this script run for multiple records at a time.

                 

                Sorry for the miscommunication, I'm trying my hardest to be clear.

                • 5. Re: Script Help
                  fitch

                  Phil's approach is the way to go. In addition to the In/Out status field, you could have an "out timestamp" field and an "in timestamp" field. I.e. you create a record each time an item goes out, then when it comes in, you change the status and set the in timestamp. (Or you can use separate date and time fields if needed.)

                   

                  Regarding the copy/paste script as posted, one option would be to simply import the found records into the other table.

                   

                  Another option, and a very useful technique to learn, is to use Set Variable to grab each field you need, then Set Field to go from the variable into the new record:

                   

                   

                  Set Variable [ $type ; Type of Equipment ]
                  Set Variable [ $id ; Serial Number ]
                  
                  Go to Layout ["Issued Equipment Inventory" ]
                  New Record/Request
                  
                  Set Field [ Equipment Model ; $type ]
                  Set Field [ Serial Number ; $id ]

                   

                   

                   

                  • 6. Re: Script Help
                    fitch

                     

                    The Loop could look like this:

                     

                    ## assumes you start with a found set of records to DELETE

                    Loop
                      Go to Layout ["Available to Distribute"]
                    Exit Loop If[ Get( FoundCount ) = 0 ]

                    Set Variable [ $type ; Type of Equipment ]
                     Set Variable [ $id ; Serial Number ]
                    Delete Record

                    Go to Layout ["Issued Equipment Inventory"]
                     New Record/Request

                     Set Field [ Equipment Model ; $type ]
                     Set Field [ Serial Number ; $id ] End Loop

                     








                    • 7. Re: Script Help
                      philmodjunk

                      Paul,

                       

                      You sent me a Private Message that fills in a lot more detail on your needs. Feel free to post an edited version of your PM here for others to comment on. Since your PM mentions that you are issuing multiple copies of the same item, I'd actually modify my approach futher to use an Inventory Log system where you log each change as a separate record in the log and use summary fields to compute the current total on hand.

                       

                      Since an item can be either returned or lost/destroyed/used up. You might need an extra field to document which items are no longer returnable in order to accurately report how many items are "out" as opposed to how many items are "Used Up".

                       

                      As I suggested in my Private Message Reply, a search of this forum for "Inventory Log" can pull up several discussions that describe this approach in more detail.

                      • 8. Re: Script Help
                        RickWhitelaw

                        I agree with Phil's approach. However, if you use a loop there must be a condition set to trigger ending the loop. Given the loop is acting on your found set, which would be finite, the Go to Record/Request (next,with"EXIT AFTER LAST"checked) should cause the loop to stop once you've reached the last record in the set. Also the suggestion of exiting the loop if Get(FoundCount)=0 would work if you're deleting records. I'll re-read your original post, but to me this seems like this method is not the best.