10 Replies Latest reply on Dec 28, 2015 8:24 AM by ElpicFayl

    Help with using a find request with a variable

    ElpicFayl

      Hello,

      I am having real difficulties with one of my scripts.

      I am trying to find if a variable can be found in a specific field of my layout, specifically some sort of login script with no security by now, I just need to have a boolean returned but find script keeps returning an error 401.

      I know there's a problem with my perform find but I can't find where.

      Here is a part of the script:

       

      Set Variable [$$Log Value: ""]

      (...empty fields check...)

      Set Variable [$$Log; Value : GetField (GLOBAL::g_log)]

      Enter Find Mode []

      Set Error Capture [On]

      Perform Find [Restore] (where my find request is Find Records RSP::log :[ == $$Log])

      If [Get (LastError)]

         Show Custom Dialog ["Error";"Error"]

         Enter Browse Mode []

         Exit Script []

      Else

         Enter Browse Mode[]

         GotoLayout ["_RSP Interface" (RSP2)]

      End If

       

       

      I tried using directly my global field or using directly a word that I know who is in my field, but to no avail, if someone can point me where I made an error, I'll be really thankfull

        • 1. Re: Help with using a find request with a variable
          wimdecorte

          ElpicFayl wrote:

           

          Perform Find [Restore] (where my find request is Find Records RSP::log :[ == $$Log])

           

           

          Do yourself a favor (and your future self when you need to troubleshoot this code a few weeks/months down the road): don't use "restore".

           

          Explicitly set the fields you want to search on after you enter find mode.

          Set Field [ RSP::log ; "==" & $$log ]

           

          It will make your script easy to read and easy to debug.

          • 2. Re: Help with using a find request with a variable
            ElpicFayl

            Thanks for the info,

            I am quite new to Filemaker, so I thought  I was stuck with this restore and forced to click on the parameter button which was quite annoying.

            Thanks to your help I managed to solve a part of this, I am now stuck with the fact that my variable doesn't seem to get the value of my global field, since if I use a hard value it works but not with my variable.

            At least even if I don't manage to solve completely my problem, I learned something!

            • 3. Re: Help with using a find request with a variable
              wimdecorte

              Drop the "GetField()" from where you are setting the variable and you should be ok.

              • 4. Re: Help with using a find request with a variable
                ElpicFayl

                I don't really understand what you are meaning.

                Global fields can be used everywhere don't they?

                So if I use one in my layout to make a form it should work, or did I missed something?

                • 5. Re: Help with using a find request with a variable
                  wimdecorte

                  GetField() will look at the contents of the field you point it to and will try to evaluate that content as a field name and try to find that field (and it fails because there is no field name that matches the value of that field).  That's not what you want.  You just want the value from the RSP::log field.

                   

                  So this will do:

                   

                  Set Variable[ $$log ; RSP::Log ]

                   

                  And yes: globals can be read from and written to regardless of your current context, but that's irrelevant in this case.  It is the GetField() call that makes it fail.

                   

                  (As an aside: if you only are going to use the $$log variable for this one script and do not need the value when the script is done, then don't use a global variable but a regular local variable: $log

                  All Variables Should Be Global... Or Not. - Soliant Consulting)

                  • 6. Re: Help with using a find request with a variable
                    ElpicFayl

                    Thanks for the link, I have already read it and applied it, since i will use $$log in other scripts.

                    At last I managed to make it work, thanks a lot!!!

                    Now I'll know that setting variables don't need GetField().

                     

                    My Final code:

                     

                    Set Variable [$$Log Value: ""]

                    (...empty fields check...)

                    Set Variable [$$Log; Value : GLOBAL::g_log]

                    Enter Find Mode []

                    Set Error Capture [On]

                    SetField [ RSP::log ; "==" & $$log]

                    Perform Find [ ]

                    If [Get (LastError)]

                       Show Custom Dialog ["Error";"Error"]

                       Enter Browse Mode []

                       Exit Script []

                    Else

                       Enter Browse Mode[]

                       GotoLayout ["_RSP Interface" (RSP2)]

                    End If

                     

                    P.S: Does your method works with a Perform Find with 2 variables?

                    PPS: If I use it on a server does each session will have its own global values and variables? or are they shared for each user?

                    • 7. Re: Help with using a find request with a variable
                      wimdecorte

                      One word of caution though: remember that in FM "context is king".

                       

                      You do your search in the RSP context:

                       

                      ElpicFayl wrote:

                       

                      Enter Find Mode []

                      Set Error Capture [On]

                      SetField [ RSP::log ; "==" & $$log]

                      Perform Find [ ]

                       

                       

                      But after the search you take the user to a different context (RSP2)

                       

                      ElpicFayl wrote:


                         GotoLayout ["_RSP Interface" (RSP2)]

                       

                       

                      Not entirely sure what you mean by this:

                       

                      ElpicFayl wrote:

                       

                      Does your method works with a Perform Find with 2 variables?

                       

                      You can use as many variables as you want/need.  Can you expand a bit on how you envision to use them?

                      • 8. Re: Help with using a find request with a variable
                        ElpicFayl

                        Sure:

                        First:

                        I have to make a draft of a login interface with no security what so ever for a client demonstration (fun fact never used Filemaker 2 weeks prior, learning as I am working), I'll have to implement the security afterwards, and will use the security and data protection of FM.

                        So for this demo I made a login page with two global fields login and password.

                        So I need to check if I can find those two values exist in my table and are correlated.

                        I know how to do it with a SQL Query, but not with FM.

                        when this is done I extract the name and first name of my table and put them in global variables to use them in my next layouts.

                        The user will then be presented with its own personalised interface.

                        So I have to find if I have an entry where my two fields log and pwd are present (I know it's not secure but my boss wants something that works in a very short delay to show to the client, we will have time to secure everything before going live).

                        If I follow you I'll do something like that

                        SetField [ RSP::name; RSP::log & "==" & $$log & " AND " & RSP::pwd & "==" & $$pwd ]

                        Perform Find [  ]

                        Secondly:

                        In fact RSP and RSP2 link to the same table, so I'll have no difficulties using what I got from my login screen it's just that in my _RSP Interface I need other relationships to display it correctly.

                         

                        Thanks again for taking time to answer me.

                        Sorry if my english is not perfect but it's not my mother language, trying my best.

                        • 9. Re: Help with using a find request with a variable
                          wimdecorte

                          ElpicFayl wrote:

                           

                          If I follow you I'll do something like that

                          SetField [ RSP::name; RSP::log & "==" & $$log & " AND " & RSP::pwd & "==" & $$pwd ]

                          Perform Find [  ]

                           

                           

                          No, you need to use two Set Fields:

                           

                          Enter Find Mode

                          Set Field[ RSP::name ; "==" & $$log ]

                          Set Field[ RSP::pwd ; "==" & $$pwd ]

                          Perform Find

                           

                          However, since you mention that you are proficient with SQL, you can use the ExecuteSQL() function instead of doing a native FM find.

                          • 10. Re: Help with using a find request with a variable
                            ElpicFayl

                            Thanks for all your help.

                            I'll use what you taught me for my script.

                            And don't get me wrong I am not proficient with SQL, I prefer to say I managed to use it, but as I had to work outside the developing world since the end of my computer studies some years ago I am a bit rusty.