9 Replies Latest reply on Nov 30, 2011 1:10 PM by Jason_Farnsworth

    Conditional Statements

    Jason_Farnsworth

      I am currently performing a loop function and it is working rather nicely, but I need to add a little complexity to it.

       

      1. There is a senerio when it is looping and performing a find that is cant find the data because it doesnt exist. It stops the script. Would I use and IF statement to get around that? I have looked at them they ask for a calculation. I am not sure how to word this calculation? Basicly if nothing is in the field move on with the loop is what I want.

       

      2. I am collecting data from two tables during this loop

      Table 1 Process ID,LineItemID, VendorID and Vendor Tier

      Table 2 MaterialID,LineItemID, VendorID and Vendor Tier

      Then I go out and create a new lineitem in different BidReq table and push all the data to that lineitem. Currently I am only Pushing Data from the Table 1. This was to test the loop and its results.

       

      I need to add the Info from Table 2 which is easy to do via another loop. However there might be some doubling up of the info, for instance The ProcessID might have the same VendorID and Vendor Tier as the MaterialID does for the same lineItemID. So if I go out and just create another loop it will simple just create a new BIDREQ lineItemsID. This will give me two of the same Vendor for Single LineItem (of the main form) if they have matching data.

       

      So how do I look for multiple vendors on the same LineItem? Then once found remove all but one? So when I do my printed report it does double the requests. Or is it better to catch the double up before it creates the new record? I would think before it creates the record to avoid having to delete anything. But I think I am back the the IF Statements to resovle it.

       

      Thanks again,

       

      Jason

        • 1. Re: Conditional Statements
          datastride

          Jason,

           

          Just add these script steps to trap for a Find that doesn’t find anything:

           

              Set Error Capture [On]

              Perform Find []

              Set Error Capture [Off]

              If[ Get(FoundCount) > 0 ]

                  << do whatever needs doing when one or more records are found >>

              End If

           

          Peace, love & brown rice,

          Morgan Jones

           

          FileMaker + Web:  Design, Develop & Deploy

          Certifications: FileMaker 9, 10 & 11

          One Part Harmony 

          Austin, Texas • USA

          512-422-0611

          • 2. Re: Conditional Statements
            pthomas

            Hi Jason,

             

            Assuming I have understood your requirements for point number 2 this is probably how I would handle it.

             

            Once you have your found set, you then want to loop through each of the records that were returned.

             

            On each record you will set the following variables:

             

              $ProcessID

              $LineItemID

              $VendorID

              $VendorTier 

              $MaterialID

             

            Then you want to go to the BidReq layout and perform a find:

             

              Go to Layout ["BidReq" (BidReq)]

              Enter Find Mode

              Set Field [BidReq::LineItemID; $LineItemID]

              Set Field [BidReq::VendorID; $VendorID]

              Set Field [BidReq::VendorTier; $VendorTier]

              Perform Find

             

            Then you want to execute the following bit of code:

             

              If [Get(FoundCount) = 0]

                New Record/Request

                Set Field [BidReq::LineItemID; $LineItemID]

                Set Field [BidReq::VendorID; $VendorID]

                Set Field [BidReq::VendorTier; $VendorTier]

              End If

             

              If [Not IsEmpty ( $ProcessID )]

                Set Field [BidReq::ProcessID; $ProcessID]

              Else If [Not IsEmpty ($MaterialID )]

                Set Field [BidReq::MaterialID; $MaterialID]

              End If

             

            So the first occurance of a particular LineItemID/VendorID/VendorTier will create the new record for you, the next occurance will just update the ProcessID or MaterialID for that existing record.

             

            Cheers,

             

            Paul.

            • 3. Re: Conditional Statements
              Jason_Farnsworth

              Morgan,

               

              Thanks for the reply, Austin - Texas I lived there for many years and loved it.

               

              On the Script Stopping, I should be a little more clear, it pauses the script and asks to continue. I am trying to get it to stop pausing for every occurance it cant find the info. What do I use to get it to realize that there is nothing there and move on with the loop before it does the find for nothing.

               

               

              Jason,

               

              Midland, Tx

              • 4. Re: Conditional Statements
                pthomas

                Hi Jason,

                 

                Turning the Error Capture on should stop the continue message coming up when the find returns no records.

                 

                Cheers,

                 

                Paul.

                • 5. Re: Conditional Statements
                  sporobolus

                  on 2011-11-30 11:37 Morgan Jones wrote

                  Just add these script steps to trap for a Find that doesn’t find anything:

                   

                        Set Error Capture  https://fmdev.filemaker.com/message/63990#63990#63990/On Re: Conditional Statements

                        Perform Find []

                        Set Error Capture  https://fmdev.filemaker.com/message/63990#63990#63990/Off Re: Conditional Statements

                   

                  you have been bitten by the wonky forum software; if you post via email, items

                  within square brackets are often turned into useless, unintended links; in

                  plain text email you can decode what was intended ("On" and "Off" at the end of

                  the links) but the web and HTML email versions of such messages will leave most

                  people quite puzzled unless they hover over the URLs and decode them

                  • 6. Re: Conditional Statements
                    Jason_Farnsworth

                    Paul,

                     

                    Thanks, it allways amazes me how simple the solutions to what I think are great big problems,

                     

                    Jason

                    • 7. Re: Conditional Statements
                      Jason_Farnsworth

                      Paul,

                       

                      Can you explain this part a little further? I am understanding this portion.

                       

                      If [Not IsEmpty ( $ProcessID )]

                          Set Field [BidReq::ProcessID; $ProcessID]

                        Else If [Not IsEmpty ($MaterialID )]

                          Set Field [BidReq::MaterialID; $MaterialID]

                        End If

                       

                      Thanks,

                       

                      Jason

                      • 8. Re: Conditional Statements
                        pthomas

                        Hi Jason,

                         

                        I was working off the assumption that the ProcessID variable will be set to no value when you are processing the Material record and the MaterialID variable will be set to no value when you are processing the Process record.

                         

                        The "Not IsEmpty" part is there to make sure that you don't replace the ProcessID or MaterialID with an empty value, this may not be an issue for you depending on how you set up the definition of the variables!

                         

                        Cheers,

                         

                        Paul.

                        • 9. Re: Conditional Statements
                          Jason_Farnsworth

                          Paul,

                           

                          Ahh ok, I understand it now. This is what I did and it Seams to work ok, well at least for the moment.

                           

                          It is possible to have one or there other and even both.

                           

                          So I created the first loop that looks for the ProcessID creates all the fields for it. The I did another loop for the MaterialID within that loop I use the

                           

                          If [Get(FoundCount) = 0]

                              New Record/Request

                              Set Field [BidReq::LineItemID; $LineItemID]

                              Set Field [BidReq::VendorID; $VendorID]

                              Set Field [BidReq::VendorTier; $VendorTier]

                            End If

                           

                          Then if none are found  it creates the record and sets all the Fields.

                           

                          Its really nice

                           

                          Thanks a bunch for the help

                           

                          Jason