8 Replies Latest reply on Jun 5, 2015 8:54 AM by docpanderson

    Is there something wrong with this code?

    docpanderson

      I asked for help a week ago concatnating a contacts name and address but now I also need to include the phone number.  I tried to follow the logic of the code I was given to just add the field Provider Phone but FM says "the specified field cannot be found," and it highlights thePhone

       

      This was the original code for concatenating the patient name and address:

      Let ( [

         theFirst = Substitute ( List ( First ) ; ¶ ; " " ) ;

        theName = Substitute ( List ( theFirst; Last ) ; ¶ ; " " ) ;

        theAddress = List ( Home Address 1 ; Home Address 2 ; Substitute ( List ( Home City ; Home State& "  "& Home Postal Code ) ; ¶ ; ". " ) )

      ] ;

      List ( theName ; theAddress )

      )

      -------------------------------------------------------------------------------------------------------------

       

      I made the substitutions of the Provider information into the above formula to read Provider off the Provider table.

      This is what I did to change it to include the phone.

       

      Let ( [

         theFirst = Substitute ( List ( ProviderFirst ) ; ¶ ; " " ) ;

        theName = Substitute ( List ( ProviderFirst;ProviderLast ) ; ¶ ; " " ) ;

        theAddress = List (ProviderAddress1 ; ProviderAddress2 ; Substitute ( List ( ProviderCity ;ProviderState& "  "&ProviderZip ) ; ¶ ; ". " );

        thePhone = Substitute ( List ( ProviderPhone );

      ] ;

      List ( theName ; theAddress ; thePhone )

      )

      -------------------------------------------------------------------------------------------------------------

      I tried to follow the logic of the code I was given to just add the field Provider Phone but FM says "the specified field cannot be found," and it highlights thePhone in its first instance.


      Please help!

      Peter



        • 1. Re: Is there something wrong with this code?
          erolst

          docpanderson wrote:

          I tried to follow the logic of the code I was given to just add the field Provider Phone but FM says "the specified field cannot be found," and it highlights thePhone in its first instance.

          Peter –

           

          Three problems:

           

          1. You should NOT use the South-Martian dialect of the FM Calculation Engine …

           

          OK, just two problems:

           

          1. You cannot declare a List() with only one item

           

          2. Substitute() needs a few more parameters; namely, a) what string to replace with b) what replacement string,

           

          But that's just why this syntax is incorrect; the real problem is that you don't need that variable.

           

          The Substitute()/List() Pattern in the variable declarations is to build lists from variable content that comes from several fields, then List() it again (now because that's your desired output format).

           

          If you have a field that goes on its own line anyway (if it does have a value), you don't need that pattern; you can simply add the field reference “ProviderPhone” to the result expression:

           

          List ( theName ; theAddress ; ProviderPhone )

          • 2. Re: Is there something wrong with this code?
            mark_baum

            Hi Peter,

             

            Concatenation is all about joining strings of characters together to make longer strings. You use the "&" operator to accomplish this. For example:

             

            "Peter"  &  " "  &  "Anderson"  gives the result "Peter Anderson".

             

             

             

            You could concatenate your address information in at least two ways.

             

            First I'll do it without the List () function:

             

            ProviderFirst & " " & ProviderLast & ¶ &

            ProviderAddress1 & ¶ &

            ProviderAddress2 & ¶ &

            ProviderCity & ", " & ProviderState & "  " & ProviderZip & ¶ &

            ProviderPhone & ¶

             

             

            Here's how I'd use the List () function to insert the same line breaks:

             

            List (

            ProviderFirst & " " & ProviderLast;

            ProviderAddress1;

            ProviderAddress2;

            ProviderCity & ", " & ProviderState & "  " & ProviderZip;

            ProviderPhone

            )

             

             

            One of the advantages of the List () function is that it doesn't add blank lines for empty values. It also looks a little cleaner.

             

            Your original examples also use the List () function to deal with possible blank values within your concatenated full name and city-state-zip.

             

            To my eye, that's a little hard to understand at first glance. An alternative is to use a Case() statement. Here's a possibility for the full name. You may think that it's too verbose -- the choice is up to you:

             

            case(

            not isempty(ProviderFirst) and not isempty(ProviderLast) ; ProviderFirst & " " & ProviderLast;

            not isempty(ProviderFirst); ProviderFirst;

            not isempty(ProviderLast); ProviderLast;

            "")

             

             

            The bottom line is that there is always more than one way to do it. I hope these alternatives help you understand why the List() function is useful and what it does for you.

             

            Cheers --

             

            Mark

            • 3. Re: Is there something wrong with this code?
              docpanderson

              Ahh I see.  Worked like a charm.  I'm so happy!  You rock!

              Peter

              • 4. Re: Is there something wrong with this code?
                docpanderson

                Mark,

                So I've learned that the little blue box is called a badge and indicates a button.  I've been trying to take the Work Address and Personal address buttons  and add more to them but when I exit layout they do not show.  Also, pushing the button causes the particular address info to be displayed.  How can I look to see how the command is worded?

                Peter

                • 5. Re: Is there something wrong with this code?
                  mark_baum

                  Hi Peter,

                   

                  I'm not sure what you are looking for exactly -- but a button can do either of two things: perform a single action or run a script. If you double-click on the button in layout mode, a Button Setup dialog will appear. The bottom portion of this dialog will indicate the action associated with the button. If it's a script, you can view the script by clicking on the script name (which appears below the Button Action).

                   

                  This is a little abstract -- see attached image for an example, where the button script is called "Navigation Button (destination)".

                   

                  Hope this helps --

                   

                  Mark

                   

                  Button action example.png

                  • 6. Re: Is there something wrong with this code?
                    docpanderson

                    Mark,

                    I see now how to go to the button setup.  I also figured out that if I want to see what the personal address button does I have to click on that button and then go into edit layout.  It's starting to come together I think.

                    Peter

                    • 8. Re: Is there something wrong with this code?
                      docpanderson

                      Mark,

                      So when I click on the Work address button of the contact starter and go to edit layout, the work address button is set to do nothing.  The Personal address button is set to Go To Object and is specified to go to "Personal Address". 

                       

                      My first question is, are the Work address and Personal address fields overlapping each other? 

                       

                      Second question is...what about the command Go To Object and "personal address"  fills in the rest of the address fields such as address 2, city, state etc.

                      Peter