10 Replies Latest reply on Sep 22, 2016 1:18 AM by ndveitch

    Using button pressed to build email list

    ndveitch

      Hi There,

       

      I need to find out if it is possible to get the state of a button and use that to build a list of emails. I have a contact layout the a button next to the email address and when the user presses the button, Outlook opens and populates the To, Subject and a default Body message.

       

      My client has asked if it is possible to have it that is it possible to press the button of a number of email addresses and then press a button at the top of the of the layout which will get all the email addresses of the pressed buttons, and then push that to the email client.

       

      I was thinking of having 2 buttons on top of each other, and when the button is pressed, it sets a check mark in the table and then hides that button and shows the second button, and the opposite would work if they had already pressed the button. Then in the Generate Email script, all I need to do would be do a find for where the fields are set and get those email addresses.

       

      Is there an easier or better way of doing this? Or am I on the right track?

        • 1. Re: Using button pressed to build email list
          David Moyer

          Hi,

          how are you storing your email list?  It's probably in a table and you can make a Value List of them.  Then display them as a checkbox set.  The text field you define as the checkbox set will hold a ¶-separated list of the emails selected.

          (As usual, there are other ways to slice this onion.)

          1 of 1 people found this helpful
          • 2. Re: Using button pressed to build email list
            ndveitch

            The layout is just a list of all the contacts for my client. I suggested the checkbox, but he asked if it could rather be a case of him pressing the email button and then it changes colour to show that it is selected. I knew I had seen it somewhere before and I have been going over my archive files and finally found it. In the FM Academy session by Kyo Logic with regards to building dashboards in FM14, John Mathewson had two buttons on top of each other, and then sets/clears a global variable to show either button.

             

            So I think I was on the right track, just needed to find where I had seen it before. Instead of setting a global variable, I could set a field. Then when my script runs, after I have gathered all the email addresses, I can clear that check mark.

             

            Thanx again for the idea about the value lists.

            • 3. Re: Using button pressed to build email list
              David Moyer

              I would use a global text field to build a list of emails.  Then you could use patterncount(email; globalList) > 0 to determine whether or not to hide the buttons.  Connecting individual buttons to the emails seems to be the difficult or labor-intensive part.

              Alternatively (to buttons), you can create a global repeating field to display your emails, and if you want separate "buttons" you can have a matching, parallel repeating field to represent the buttons.  You can use conditional formatting to change fill and font colors for individual repetitions.  e.g. to change every third repetition, the condition would be not Mod(Get(CalculationRepetitionNumber); 3)

              • 4. Re: Using button pressed to build email list
                philmodjunk

                Your button click can perform a script that adds or removes the current record's email address from a return separated list in a global variable--which mimics the action of a check box.

                 

                A conditional format on the button can change fill and/or text color if the current record's email address is in the list in that global variable.

                 

                When it comes time to send the email, your script can set the "TO" box in Send Mail to the list of email addresses, using a calculation with substitute replacing the returns with email delimitters--usually a semi-colon.

                 

                Your button's script might do this:

                 

                If [ IsEmpty ( FilterValues ( YourTable::EmailAddress ; $$EmailAddressList ) ) ]
                   #Not in list, so add it
                   Set Variable [ $$EmailAddressList ; value: List ( $$EmailAddressList ; YourTable::EmailAddress ) ]

                Else

                   #In List, Remove it

                   Set Variable [$$EmailAddressList ; value: //use calc shown below here ]

                End If

                 

                //Calc to remove address from list

                Let ( $$EmailAddressList = Substitute ( ¶ & $$EmailAddressList & ¶ ; YourTable::EmailAddress ; ¶ ) ;

                         $$EmailAddressList = Middle ( $$EmailAdressList ; 2 ; Length ( $$EmailAddressList ) - 2 )

                      ) // Let

                • 5. Re: Using button pressed to build email list
                  ndveitch

                  HI PhilMod,

                   

                  Thank you so much for the script. I think I am doing something wrong thou. Adding names to the list works fine, but removing them doesn't work as well.

                   

                  I tried this and it seemed to work,

                   

                  Set Variable [ $$EmailAddressList ; Value: Substitute ( $$EmailAddressList ; Contact::Email ; "" )   

                   

                  /*Let (

                  $$EmailAddressList = Substitute ( ¶ & $$EmailAddressList & ¶ ; Contact::Email ; ¶ ) ;

                  $$EmailAddressList  = Middle ( $$EmailAddressList ; 2 ; Length ( $$EmailAddressList ) - 2 )

                  )

                  */

                   

                  Just doing the substitute seemed to do the trick.

                  • 6. Re: Using button pressed to build email list
                    philmodjunk

                    It works most of the time, but is not as "safe" as the other approach. It can screw up your email list of addresses.

                     

                    If you had two email addresses such as:

                     

                    MaryJane@domain.com

                    Jane@domain.com

                     

                    both in your list,

                     

                    Then removing Jane@domain.com from the list corrupts the email address for MaryJane by removing "Jane@domain.com" from that address as well leaving an invalid email address of just "Mary".

                     

                    Note that:

                    /*Let (

                    $$EmailAddressList = Substitute ( ¶ & $$EmailAddressList & ¶ ; Contact::Email ; ¶ ) ;

                    $$EmailAddressList  = Middle ( $$EmailAddressList ; 2 ; Length ( $$EmailAddressList ) - 2 )

                    )

                    */

                    is enclosed in /* comment brackets */

                    and thus will do nothing at all.

                    • 7. Re: Using button pressed to build email list
                      ndveitch

                      I left the portion /* ... */ in so you could see that I did try it, but I keep getting the result of "0" when i have the let statement in, and I dont understand the Let statement well enough to debug why I was getting the 0 and not the reduced list.

                      • 8. Re: Using button pressed to build email list
                        David Moyer

                        Hi,

                        I want to try to help too ...

                        1. make sure you interpret Phil's pseudocode properly (with double-quotes):

                        $$EmailAddressList = Substitute ( "¶" & $$EmailAddressList & "¶" ; Contact::Email ; "¶" )

                        2. I think that this result might leave you with leading ¶'s (or, with the second step, a truncated first line), especially if the first value is the one removed - I'm not sure.  Anyhoo, try this as a single step:

                        $$EmailAddressList = Substitute ( "¶" & $$EmailAddressList & "¶"; "¶" & Contact::Email & "¶"; "" )

                        • 9. Re: Using button pressed to build email list
                          philmodjunk

                          It should work as written. I use this all the time. Single instances of the pilcrow do not need to be enclosed in quotes, though doing so as Michael has written does not cause a problem.

                           

                          The Let function first puts a return at the beginning and end of the text so that substitute can replace the email with enclosing returns with a single return. The Middle function then strips off the extra returns at beginning and end so they won't cause an issue later.

                           

                          However, looking up my past work shows that my memory failed on me and there is an error in the calculation. This is the corrected calculation:

                          Let (

                          $$EmailAddressList = Substitute ( ¶ & $$EmailAddressList & ¶ ; ¶ & Contact::Email & ¶ ; ¶ ) ;

                          $$EmailAddressList  = Middle ( $$EmailAddressList ; 2 ; Length ( $$EmailAddressList ) - 2 )

                          )

                          1 of 1 people found this helpful
                          • 10. Re: Using button pressed to build email list
                            ndveitch

                            Thank you so much PhilMod. If I could press the Helpful button a million times I would. I saw in your demo file that in the Let() in the calculation section there was no " $$EmailAddList = " it just said Middle ( .... ). Once I took the $$EmailAd.. out, I stopped getting hte "0" result.

                             

                            Thank you again.