Email address: connie.rxxx@gmail.com
Phone number: 9171231234
Zip code: 12345
Message: Hi, we’re in need of xxx
Interested In: xxx, zzz
EDIT:
The email is a link actually
Name: Connie R
Email address: connie.rxxx@gmail.com
Phone number: 9171231234
Zip code: 12345
Message: Hi, we’re in need of xxx
Interested In: xxx, xxx
The rest is just putting aside the familiar (but complicating, and very time-consuming) search and replace habit, and turning to splitting as a simpler and more powerful default.
Can provisions be make in the code that, if there was no data entered for one of the 'fields' (in this case - message) that it would not error and just set that 'variable' to 'empty'?
Or should I simply put an if statement that if any of the 'variables' are empty, they get set to 'empty'?
I think I am not being very clear here....
Using the following block of text I get the included error in the log.
Name: Chris
Email: Chrisxxxx@yahoo.com
Phone: 1231231234
Zip Code: 12345
Message:
Interested In: House Cleaning Services
2024-08-24 12:31:39 Execute macro “Contact form regex 2024_08_19 ∑ K0315” from trigger Do Script
2024-08-24 12:31:39 Action 16119975 failed: Search Regular Expression failed to match ^([^ ]+) (.+)$
2024-08-24 12:31:39 Search Regular Expression failed to match ^([^ ]+) (.+)$ in macro “Contact form regex 2024_08_19 ∑ K0315” (while executing Search Variable “Client_Full_Name” Using Regular Expression (ignoring case)).
NOTE: Ignore the Client_Full_Name error, I have overcome that part of it.
ah, I'm using Filemaker Pro using applescript to get a KM variable, when that variable is empty I get an error from Filemaker Pro. So it must be KM via applescript not liking a blank variable?
--FMP Field from KM variable
tell application "Keyboard Maestro Engine"
set Client_First_Name to value of variable "Client_First_Name"
set Client_Last_Name to value of variable "Client_Last_Name"
set Client_Email_Home to value of variable "Client_Email_Home"
set Client_Phone to value of variable "Client_Phone"
set Client_Zip_Code to value of variable "Client_Zip_Code"
set Client_Message to value of variable "Client_Message"
end tell
--display dialog Client_Full_Name
tell application "FileMaker Pro"
set cell "First Name" of current record to Client_First_Name
set cell "Last Name" of current record to Client_Last_Name
set cell "Email Home" of current record to Client_Email_Home
set cell "Mobile Phone" of current record to Client_Phone
set cell "Home Postal Code" of current record to Client_Zip_Code
set cell "Directions" of current record to Client_Message
end tell
This is done after I have set a KM Variable to %Variable%local_Value[5]\n%
Even though your problem is solved, may I be permitted to show another solution? This works fine for me, but if your data can contain errors, you should add some error handling code. The simplest error handling would be just to set the flag to ignore errors on the Search action, which seems to work for me.
You could also "modify" the variable names by inserting the following statement in-between the two internal actions, like this:
You can't get the value of a an empty variable. "Existence" is a bit vague in KM (it depends on where, and how, you look!), but the wiki tells us that:
Global Variables continue to exist (remained stored) until their value is set to the empty string
...and you're setting Client_Message to en empty string when there is nothing in your text block's line after "Client Message: ".
You get round this by using getvariable which handles empty/non-existing KM variables for you by returning an empty string:
tell application "Keyboard Maestro Engine"
set Client_First_Name to getvariable "Client_First_Name"
set Client_Last_Name to getvariable "Client_Last_Name"
set Client_Email_Home to getvariable "Client_Email_Home"
set Client_Phone to getvariable "Client_Phone"
set Client_Zip_Code to getvariable "Client_Zip_Code"
set Client_Message to getvariable "Client_Message"
end tell
Generally, always use getvariable rather than the older value of variable construct.