1 2 Previous Next 17 Replies Latest reply on Feb 22, 2017 2:34 AM by tays01s

    Go to related record

    tays01s

      I've script where its 2nd part if it finds no records, it should make one. Instead, Data Viewer indicates it as finding 6 User records. I'd used this script in a very similar solution without problem, but this appears not be be moving it's focus off the User layout/table. Any obvious checks I should make?

      Go to Layout [ “Users” (Users) ]

      Enter Find Mode [ ]
      Set Field [ Users::Email_check; "==" & Quote ($EmailFind) ]

      Set Error Capture [ On ]
      Perform Find [ ]
      If [ Get(FoundCount)=0 //safer test than 'is empty' ]

      New Record/Request

      End If

       

      Go to Related Record [ From table: “Licenses”; Using layout: “Licenses” (Licenses) ] [ Show only related records ]

      Enter Find Mode [ ]

      Perform Find [ ]
      If [ Get(FoundCount)=0 ]

      New Record/Request

      End If
      Go to Layout
      [ “Users” (Users) ]

        • 1. Re: Go to related record
          BruceRobertson

          This script makes absolutely no sense at all.

           

          You never define the variable $EmailFind; so you will ALWAYS fail.

           

          You then create an empty record.

          In the second part of the script, you attempt to go to a related records.

          But since the User record is new; and empty; there are no related records.

          And therefore you will never go to other layout.

          Secondly, if there WERE related records; you are ignoring them. You are setting up another failed find.

          Instead, you remain on the original layout; enter find mode; enter NO search criteria; and therefore try to find nothing.

           

          "I'd used this script in a very similar solution without problem"

           

          Extremely doubtful.

          But anyway: what are you really trying to do?

          • 2. Re: Go to related record
            tays01s

            In trying to cut down extraneous detail I comprehensively gave you too litte info. Full script below, but what I'm trying to do is check whether there's a matching User already, if not, create a new one AND create a License record. I realise now I should probably 'Exit' if there was already a User record.

             

             

            Go to Layout [ “Users” (Users) ]
            Set Variable [ $EmailFind; Value:Users::Email_in ]
            Set Variable [ $Lic_nFind; Value:Users::Lic_n ]
            Set Variable [ $Input; Value:Users::Input ]
            Enter Find Mode [ ]
            Set Field [ Users::Email_check; "==" & Quote ($EmailFind) ]

            Set Error Capture [ On ]

            Perform Find [ ]
            If [ Get(FoundCount)=0 //safer test than 'is empty' ]

            New Record/Request
            Set Field
            [ Users::Input; $Input ]
            Set Field [ Users::Email_check; $EmailFind ]

            End If

             

            Set Variable [ $Lic_item_ym; Value:Items 3::Item_ym ]

            Go to Related Record [ From table: “Licenses”; Using layout: “Licenses” (Licenses) ] [ Show only related records ]

            Enter Find Mode [ ] Perform Find [ ]
            If [ Get(FoundCount)=0 ]

            New Record/Request
            Set Field
            [ Licenses::_ItemsID; Users::Lic_n ]

            Set Field [ Licenses::Input; Users::Input ]
            Set Field [ Licenses::Item_ym; Users::Item_ym ]

            End If
            Go to Layout
            [ “Users” (Users) ]

            Commit Records/Requests

            • 3. Re: Go to related record
              siplus

              If you have a relationship from users to licenses which is allowed to create new records in licenses, then once you create a new record in users you can create a new related record in licenses without leaving the users layout, doing finds and or going to related records.

              • 4. Re: Go to related record
                BruceRobertson

                You don't commit your new User record.

                Your second find (in Licenses) still doesn't do anything. There is no search criteria.

                 

                You don't test for the existence of related License records; therefore your GTRR to Licenses may fail.

                And therefore your second new record command occurs in Users, since you never left.

                • 5. Re: Go to related record
                  philmodjunk

                  And there is nothing in your script assigns values to your variables. Either you have still left out script steps or you are referencing variables that do not exist and which are therefore empty.

                   

                  The simplest way to check to see if any related records exist:

                   

                  If [ not isempty ( relatedTableOccurrence::primaryKey ) ]

                  • 6. Re: Go to related record
                    tays01s

                    Italics shows my changes, where initially User:: Email_in < User:: Email_check. Unfortunately the script neither spots an existing User (and goes ahead and generates a new record) and fails to set the fields to the variables generated at the beginning.

                     

                    Freeze Window

                    Set Variable [ $EmailFind; Value:Users::Email_in ]

                    Set Variable [ $Lic_nFind; Value:Users::Lic_n ]

                    Set Variable [ $Input; Value:Users::Input ]
                    If [ IsEmpty (Users 2::__ID) ]

                    New Record/Request
                    Set Field
                    [ Users::Input; $Input ]
                    Set Field [ Users::Email_check; $EmailFind ]

                    End If

                    Commit Records/Requests

                    Set Variable [ $Lic_item_ym; Value:Items 3::Item_ym ]

                     

                    Go to Related Record [ From table: “Licenses”; Using layout: “Licenses” (Licenses) ] [ Show only related records ]

                    If [ IsEmpty(Licenses::__ID) ]
                    New Record/Request
                    Set Field
                    [ Licenses::_ItemsID; Users::Lic_n ]

                    Set Field [ Licenses::Input; Users::Input ]
                    Set Field [ Licenses::Item_ym; Users::Item_ym ]

                    End If
                    Go to Layout
                    [ “Users” (Users) ]

                    Commit Records/Requests

                     

                    • 7. Re: Go to related record
                      tays01s

                      I've spotted some stupid errors on my part, eg. reverting to using field names to set other fields when I'd earlier generated variables to do this. Daft !

                      • 8. Re: Go to related record
                        BruceRobertson

                        Still not listening. Your GTRR makes no sense.

                        • 9. Re: Go to related record
                          BruceRobertson

                          And now we are not sure where you are. Even if is supposedly fixed; please show it.

                          And of course if NOT fixed; please show it.

                          • 10. Re: Go to related record
                            philmodjunk

                            A check for a related record in licenses should be done before using GTRR in an attempt to bring up the related record, not afterwards.

                            • 11. Re: Go to related record
                              tays01s

                              Sorry for the delay; I was experimenting.

                               

                              So you are saying that instead of:

                              1. Go to Related Record [ From table: “Licenses”; Using layout: “Licenses” (Licenses) ] [ Show only related records ]

                              2. If [ IsEmpty(Licenses::__ID) ]

                              3. Go to Layout [ “Licenses” (Licenses) ]

                              4. New Record/Request

                               

                              It should be:

                              1. If [ IsEmpty(Licenses::__ID) ]

                              2. Go to Related Record [ From table: “Licenses”; Using layout: “Licenses” (Licenses) ] [ Show only related records ]

                              3. Go to Layout [ “Licenses” (Licenses) ]

                              4. New Record/Request

                               

                              ??? However, I have now got the former working, but the latter doesn't.

                               

                              • 12. Re: Go to related record
                                philmodjunk

                                If [ Isempty

                                   Go to layout

                                    new record

                                Else

                                   GTRR

                                End If

                                 

                                And as Bruce has commented, it would be very helpful to know what layout (and the table occurrence one which it is based that is current before you perform the script.

                                 

                                If there is no related record in licenses, GTRR silently returns and error code and does nothing else. That leaves you on your current layout when New Record is executed, which could then be creating your new record in the wrong table.

                                • 13. Re: Go to related record
                                  BruceRobertson

                                  Phil's reply is good.

                                  1. It is not helpful to show partial script and most especially, to NOT indicate where your END IF statement occurs.

                                  2. Please always include the COMPLETE script.

                                  3. Is there some way we can encourage you to actually think about how these things work?

                                  4. It would also be helpful if you could explain to yourself and to us, what the logic is, while NOT using FileMaker scripting language.

                                   

                                  This might be what you are trying to do; but I can't be sure:

                                   

                                  Does a user record exist for this email?

                                  If not; create one?

                                  Is there some chance the user already exists but this email represents a CHANGE for that user?

                                  Licensing records: well; we have no idea at all here.

                                  What is the connection between a user and a license?

                                  Is there some way a license record could already exist for this user, even if we have just created the new user record?

                                  Or does new users ALWAYS == add new license record?

                                  • 14. Re: Go to related record
                                    BruceRobertson

                                    Regarding this:

                                     

                                    1. If [ IsEmpty(Licenses::__ID) ]

                                    2. Go to Related Record [ From table: “Licenses”; Using layout: “Licenses” (Licenses) ] [ Show only related records ]

                                    3. Go to Layout [ “Licenses” (Licenses) ]

                                    4. New Record/Request

                                     

                                    Where is your End IF????

                                     

                                    Consider this:

                                    1. If [ IsEmpty(Licenses::__ID) ] (no related license record exists)

                                    2. Set all required variable for this operation. THEN

                                    3. Go to Layout [ “Licenses” (Licenses) ]

                                    4. New Record/Request

                                    5. Set fields (which fields? using which variables?)

                                    6. Commit record

                                    7. #OK done creating license record

                                    8. Go to Layout [ some layout based on Users ]

                                    9. ELSE

                                    10. # A related License record DOES exist. Therefore do nothing? Create a new license record anyway?

                                    11. End If

                                    1 2 Previous Next