Jump to content

e-mail script


faaslave

This topic is 6287 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hello all,

It seems my problems are endless, I guess that is what makes this fun.

I have two emails for every one in my database. A home email and a work email. When I send email to all members, I want it to use the home email if available, then if there is no home email, use the work email.

Here is what I have. It should work, but it does not include the people with only work emails when I run the script.

Go to layout ["members" (MEMBERS)]

Show all records

Commit Records/Requests []

if [/*IsEmpty(MEMBERS::H email)*/]

Go to Field [memberS::W email]

if [/*IsEmpty(MEMBERS::W email)*/]

Show Custom Dialog ["Message"; "blah blah"]

Else

Go to field [memberS::W email]

Send Mail [To: MEMBERS::W email]

End if

Else

Send Mail [memberS::H email]

If [Get(LastError)]

Show Custom Dialog ["Message"; "blah blah"]

End if

End if

What am I missing?

Thanks Dave

Link to comment
Share on other sites

Take the /* and */ out of the If statements. Those are comment marks, therefore your staement is not being qualified.

That usually happens when you copy a statement from one script to another or from a script from another table.

I learned that the hard way as well. :

Link to comment
Share on other sites

I think this will do what you want with changes:

Go to layout ["members" (MEMBERS)]

Show all records // [color:blue]Do you really want to send to ALL the records in the database?

Commit Records/Requests [] // [color:blue]I don't think you need to do this

[color:red]Change to:

Set Variable:$emailaddress

If [isEmpty(MEMBERS::H email)] AND [isEmpty(MEMBERS::W email)]

Show Custom Dialog ["Message"; "blah blah"]

Endif

if [Not IsEmpty(MEMBERS::H email)]

Set Field[(MEMBERS::H email; $emailaddress)

Send Mail [To: $emailaddress]

Else

Go to field [memberS::W email]

Set Field[(MEMBERS::W email; $emailaddress)

Send Mail [To: $emailaddress]

End if

If [Get(LastError)]

Show Custom Dialog ["Message"; "blah blah"]

End if

I'm sure I have one or two mistakes that someone with greater experience will correct but, I hope this helps you go in the right direction.

Link to comment
Share on other sites

Thanks for reply.

I didn't even notice the */'s, thanks

When I try to type

Set Field[(MEMBERS::H email; $emailaddress)

it doesn't buy this

I think your script looks great, but this one line I can't seem to get in correctly

Thanks, Dave

Link to comment
Share on other sites

I did manage to get in typed in as you suggested. It is still not working though. I have gone through it many times and it seems to make sense to me.

As a matter of fact, when I run this script, it removes the home email of my first member. Then it comes up with the mail program and no names listed.

I have tried to copy and paste the script in here, but the paste does not work as well. Filemaker is fighting me. I have attached the script.

Thanks Dave

FAAMA.pdf

Edited by Guest
Link to comment
Share on other sites

What your script does is define an empty variable and then sets your field to that variable, i.e. you're setting your field to empty. You need to turn that around. Try this:

Set Variable [ $emailaddress ; MEMBERS::H email ]

If [ IsEmpty($emailaddress) // home was empty, try work

. Set Variable [ $emailaddress ; MEMBERS::W email ]

. If [ IsEmpty($emailaddress) // home and work were both empty

. . Show Custom Dialog [ Title: ""; Message: "There is no email address for this record. Please try again after entering an address."; Buttons: “OK” ]

. . // You don't need OK and Cancel if they both do the same thing

. . Exit Script

. End If

End If

Send Mail [ To: $emailaddress ]

Note (about the attached PDF) that I changed your dialog, since "check that your email software is installed correctly" isn't relevant to whether the address is blank.

Also note that if you want to show your own error messages based on Get(LastError), you should Set Error Capture [On] at the start of the script so that FileMaker's native error dialogs are suppressed.

Link to comment
Share on other sites

One small problem. I have 21 records in my test set of records. One has a W email and the other 20 have H email.

When I run the script with the new scripting listed above, It puts the record with the W email in the To: message 21 times. The other records don't show up in the To: address line?

Here is the file, the scipt is "email all members"

Dave

FAAMA.1.4local.fp7.zip

Edited by Guest
Link to comment
Share on other sites

That script doesn't loop through all records. It just sends an email for whatever record you're on.

You need to wrap the script in:

GoTo Record [first]

Loop

... most of your script

GoTo Record [Next, exit after last]

end loop

Or you need to create a calculated field instead of using the variable and then use the Send Email options to generate multiple emails with the calculated field as "To", if you want to avoid the looping.

Link to comment
Share on other sites

Well I tried the calc method and it works great!!!!

I could not get the loop method to work, and I want to understand why. If you don't mind, I have attached the new file with both scripts. The one that works, email all members w/calc, and email all members (the one with the loop).

I guess I just want to understand variables

Thanks Dave

FAAMA.1.5local.fp7.zip

Link to comment
Share on other sites

You needed to put the "send email" in the loop (see screenshot).

The variable gets set and overwritten for each record you visit.

What was your intent: to add the email address to the variable for each contact? Or to set it for each contact and send each one an email based on that?

f_20060524_00.jpg

Link to comment
Share on other sites

Thank you very much, one email to all of them.

So these varaibles only live within a script, there is no field associated with them? I think I understand it. I can see where this variable will come in handy.

Dave

Link to comment
Share on other sites

The problem is that each time it runs through the loop it is creating a new email. Can the variable store the results after completing the loop, so you end up with

To: john, dave, jim, etc.?

Link to comment
Share on other sites

There are two kinds of variables: local and global. Both are defined within a script using the Set Variable script step. The difference is that local variables exist only while the script is running, but global variables persist and remain usable in the file where they were defined, until that file is closed.

Local variable names start with $ and globals start with $$, that's all there is to defining one or the other. In your script above, the variables are local.

A variable doesn't belong to a particular record, so in that sense even a "local" variable behaves like a global field.

Now to answer your next question, yes: you could append the results inside the loop. I'd probably use one variable to do the testing and grab the single email address, and another variable to append.

However, might want to take a step back at this point and review what you're trying to accomplish. E.g., if you're trying to send to a group of found records, do you really want it to abort the whole process if one record has no address? Also: did you notice FileMaker 8 now has an option in the Send Mail step, "for each message, collect addresses across found set" -- it would seem that this would obviate the need for a loop at all. And you don't even necessarily have to make a calculated field for each record (home vs. work) -- you can do the calc right within the email script step:

Case ( not IsEmpty( MEMBERS::H email ) ; MEMBERS::H email ; MEMBERS::W email )

I have not tested this, but it appears that in FileMaker 8 the entire script could be accomplished with a single Send Mail script step!

Link to comment
Share on other sites

Wow, the case statement is a real clean way to make this work. The calc way worked too but involved more scripting. The variable way still doesn't work. Can a variable store the results of a record and keep appending the results as it loops through the records, or is the variable being replaced each time the next record puts a result into the variable?

Thanks alot, your last example worked great.

Dave

Link to comment
Share on other sites

sure, you can append to a variable. But you'll need to change your looping routime that checks for email addresses.

loop

...

if[not isempty(home email)]

setVariable ($email = $email &";" & home email

elseIf[not isempty(work email)]

setVariable ($email = $email &";" & work email

end if

...

end loop

The Send Email then goes back outside the loop

Link to comment
Share on other sites

Your missing the record navigation script steps.

(that's what I implied with the "..." in the loop)

After "show all records", do a goto record[first}

just before exiting the loop do a goto record[next, exit after last]

Link to comment
Share on other sites

  • 2 weeks later...
  • 7 months later...
  • Newbies

i know this is an old bump/blast from the past, but thank you everyone in this thread for this script.

it's very similar to what i was looking for and i was able to tweak it a little so it matched my needs exactly.

we have customer contact list in fm85. most contacts have emails but not every contact wants to receive email announcements. there's another field for each contact about whether or not to receive email announcements. fm85's email function doesn't support this "extra" check. this script got me headed in the right direction.

thanks again!

Link to comment
Share on other sites

This topic is 6287 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.