6 Replies Latest reply on May 25, 2016 2:58 AM by cillion

    Create new person if he dont exist

    cillion

      Hi.

      I have a layout called "Project", on this layout I have a portal that shows a list of persons that have been added to this project. "Person" is a related table.

       

      I need a script that when the user is trying to create a new person from "project" check if the person first and lastname already exist, if not he create the person and adds him to the portal-list on "project". If the person hi is trying create exist, I can just show an custom message.

       

      Here is the view on "Project":

      addnewperson.jpg

      Do somebody have and example of this kind of script?

        • 1. Re: Create new person if he dont exist
          erolst

          Maybe create a relationship with a new Person TO where

           

          Project::z_create_firstName = People_check::nameFirst

          Project::z_create_lastName = People_check::nameLast

           

          and check with

           

          If [ not IsEmpty ( People_check::primaryKey ) ]

            Show Custom Dialog [ "Name already exists" ; … ]

           

          Make sure to auto-Trim() your entry fields.

           

          You could also try a SQL query, but that is not everyone's cup o' tea.

          • 2. Re: Create new person if he dont exist
            cillion

            Thanks for your input erolst. Do you have an example for this? It looks like this will only check if the firstname and lastname are unique seprately. It should be the combination of first and last that should be unique

            • 3. Re: Create new person if he dont exist
              erolst

              slaekke wrote:

              It looks like this will only check if the firstname and lastname are unique seprately.

              Is that your considered opinion as an expert, or did you test it empirically?

               

              OK, kidding aside: relationship predicates in FileMaker are combined with a logical AND, i.e. all conditions must be true for a match.

               

              See here:

               

              Screen Shot 2016-05-15 at 23.58.50.png  Screen Shot 2016-05-15 at 23.59.14.png

              This is a hide condition; for your scripted test, you need to use not IsEmpty().

              • 4. Re: Create new person if he dont exist
                cillion

                I tried this in Webdirect. And it will result in an bug that it dont closes the popover, and it is not close it before refreshing the page. Any idea why?

                this is my script:

                2016-05-25_09-47-11.jpg

                • 5. Re: Create new person if he dont exist
                  erolst

                  1. Why are you doing this the hard way, instead of using a relationship?

                   

                  2. Your script is hard to follow because there's much redundancy; e.g. you're closing the popover and resetting the globals in 3 places. Since it seems you want to do that in any case, why not do it instantly after launching the script? (and you should add error trapping: if someone launches the script without having both fields filled in, this is all for the birds.

                   

                  3. If your AND search didn't find a match on two fields, there cannot be a validation error for the uniqueness of both fields combined (if that is what you're doing).

                   

                  4. You may want to consider the scenario where two people have the same name. What then?

                   

                  5. You should Trim() the names in the database (via auto-enter) and the input in the globals (in the script); if someone types a blank somewhere, all bets are off.

                   

                  I suggest (pseudo-code)

                   

                  Check input

                  If [ inputIsNotOK ]

                  Dialog [ missing values etc. ]

                  End If

                  Set Variables to Trim()med versions of input globals

                  Close popover

                  Clear globals

                  Set Variable [ $candidateCreated ; False ]

                  Go to Layout

                  Perform the Find

                  If [ error = 401 ]

                    Create new record with names

                    If [ error = 504 ]

                      Delete Record

                    Else

                      Set Variable [ $candidateCreated ; True ]

                    End If

                  End If

                  Go to original layout

                  Dialog [ If [ $candidateCreated ; "createdMessage" ; "alreadyExistsMessage" ) ]

                  1 of 1 people found this helpful
                  • 6. Re: Create new person if he dont exist
                    cillion

                    Thanks for the input. My script runs perfectly fine in PRO/advanced, but not in webdirect. The popover hangs in webdirect and resulting in bug. So there must be something that is not sopported in webdirect.

                    I need to stick to the script intill I get more experimence, I understand mine