4 Replies Latest reply on Dec 22, 2009 3:02 PM by Jeff123

    Email selected contacts using checkbox and script

    Jeff123

      Title

      Email selected contacts using checkbox and script

      Post

      I am attempting to create a script but cannot figure out how to work it.  I think I am doing it too simple.

       

      I have a field of checkboxes (named Email Boxes) with values:

      Contact 1

      Contact 2

      Contact 3

       

      This goes for like 5 contacts that are on the same particular record.  The email fields for those records are "Contact Management::Email 1", "Contact Management:: Email 2", and so forth.

       

      My non working script looks like this (this is the first email and second part, it is duplicated for each of the other e-mails)

       

      If [Contact Management::Email Boxes = "Contact 1"]

      Send Mail [Send via E-mail Client; To: Contact Management::Email 1]

      End If

       

      If [Contact Management::Email Boxes = "Contact 2"]

      Send Mail [Send via E-mail Client; To: Contact Management::Email 2]

      End If

       

      My ideal goal is that when specific button is clicked it will open up Apple Mail with only the contacts selected loaded in the "To" field of an e-mail.

       

      I would also like a "Select all" feature, but that I haven't even gotten to that step yet.

       

      Thanks.  This forum is so helpful for a newbie like me! 

       

        • 1. Re: Email selected contacts using checkbox and script
          philmodjunk
            

          Something doesn't add up here and that "something" should explain why it doesn't work. :smileywink:

           

          A value list of check boxes such as

          Contact 1

          Contact 2

          Contact 3

           

          Is applied to a single field. If you click Contact 1 and then click Contact 2, the field you formatted with this value list in Field/Control | Setup... stores both values separated by a carriage return:

          Contact 1 <return>

          contact 2

           

          Yet you describe having at least three different fields: Email 1, Email 2, etc.

           

          It sounds like you should have a portal or related contact records with a separate, check box formatted selection field to the left of each Contact field in the portal.

           

          There are several ways to set up this selection field depending on whether you need to implement this in a database that is being shared by several users over the network or not.

          • 2. Re: Email selected contacts using checkbox and script
            Jeff123
              

            How about if I used multiple fields? I *think* that is what you meant.  So for example I now have fields called "Email Box 1", "Email Box 2", etc.  Then each will only have one option.  Would a script work then.  What I tried was:

             

            If [Contact Management::Email Box 1 = 1]

            Send Mail [Send via E-mail Client; To: Contact Management:: Email 1] 

            End if

             

            But that will open the new blank email for that contact no matter if the box is checked or not.  My train of thought was that if I do " = 1" that means "true", as in if it is checked off.

             

            I am also assuming if I did it this why I would have to use "Else if", but not sure what I would put to make the script do nothing and continue to run (because I would want it to continue the script looking to see if any other contacts are checked). 

             

            Edited:

            This is only a local database 

            • 3. Re: Email selected contacts using checkbox and script
              philmodjunk
                

              Contact Management::Email Box 1 = 1

               

              will be true only if the value entered in Email Box 1 is the value 1.

               

              I'm not suggesting multiple fields, in this case, multiple fields can complicate your scripts as you'll have to separately check each email field.

               

              Instead define a table of email Addresses. You should already have a ContactID serial number field in Contact Management.

               

              Set up a relationship to this new table like this:

              Contact Management::ContactID = Email Addresses::ContactID (enable "Allow creation of records via this relationship for Email Contacts)

               

              Display these Email Contacts in a portal on your layout. Not only is it easier to pull up a list of selected contacts from this table, you can now have 5, 6, 7 or more such contacts if needed.

               

              There are at least two ways to set up selection fields that build the list of selected email addresses. Which is the right choice depends on your database design. Is this a database that will be used by more than one user at the same time or is strictly a single user database?

               

              Let me know the answer to that and I'll add the next part.

              • 4. Re: Email selected contacts using checkbox and script
                Jeff123
                   Ok, I have everything set up like that now.  I have the local FM10 and only using it for one machine, one user.  Thank you a lot for all this help, btw.