I am trying to write a set of hotkeys to streamline and automate a Data Entry task. We keep customer records in a webbased CRM program called ONYX and we often need to send this data to another webform. This requires that we handkey all this data a second time, which is "High Tomfoolery" IMHO. So using my newly learned skills inside AHK_L (AutoHotkey110703_Install.exe) and Regexmatch I have written a script that should do the job. First I have it highlight and copy the customer record from ONYX and append it into a tasty txt file. Then from there I have it Parse and Regexmatch for different strings and store them to VARs for later outputting into a webform. I have got it up but am stymied in a few spots. I have attached the AHK file as well as a mocked up data source to play with.
Issue #1, My Customer's First and Last Name will always be located before this "Needle Value" "(ID:" that you see on the 1st line of the ONYXRaw1.txt. I cannot figure out how to make the script to "backtrack from that Needle Value 'anchor' to collect the names.
Issue #2, Sometimes the customer has 2 address lines and I cannot get my address parsing loop to work right. Since it works 100% correctly in another AHK script (doing a different job) I am a bit stumped what I have done wrong.
Issue #3, When getting the Telephone number parsed the sucker works right with I Manually set the values inside the script see Purple section on CTRL+SHIFT+0 (Zero) MACRO#2. But when I use a FileRead from the txt to load from the txt file it fails. See Red section.
;[color=#FF0080] CRTL+SHIFT+o (o as in Oscar)[/color] Start in Outlook Shared ROLE account for WGU Regs. Opens Email, strips the empty spaces and white spaces, parses the data for student info, stores that info to VAR set, Overpastes info back into Outlook and saves it.
^+o::
KeyWait, o
Clipboard =
;WinActivate, ahk_id %Onyx1%
;Sleep 500
;MouseClick, Left, 154, 183, , ,D
;Sleep 250
;MouseClick, Left, 1381, 524, , ,U
;Sleep 500
;Send ^c ; Highlight All and Copy
;ClipWait
;ONYXRaw := Clipboard
;FileDelete, ONYXRaw1.txt
;FileAppend, %ONYXRaw%, ONYXRaw1.txt ;create raw txt file with the ONYX Info
;Sleep 250
;MouseClick, Left, 660, 500
[color=#FF0080]FileRead, ONYXdata, ONYXRaw1.txt[/color]
; This section catches & stores the address first, it can tell if there are 2 or 3 address lines.
Loop, parse, ONYXdata, `n, `r
{
if inStr(A_LoopField, "Home Address")
nexlineIsAddress := 1
else if (nexlineIsAddress)
{
address := A_LoopField
nextlineMightBeAddress2 := 1
address2 := ""
nexlineIsAddress := 0
continue
}
else if RegExMatch(A_LoopField,"^(.*) ([A-Z]{2}), (\d{5})",_)
{
City := _1, State := _2, ZipCode := _3
nextlineMightBeAddress2 := 0
}
else if (nextlineMightBeAddress2)
{
_address2 := A_LoopField
nextlineMightBeAddress2 := 0
}
}
; This next section catches & stores the First Name, Last Name, ONYX email address, Student ID#, and Telephone Number.
Loop, parse, ONYXdata, `n, `r
{
#name := "Name:\s+?(?P<fName>\w+)\W+?(?P<lName>.*?)\r?\n"
#email := "Email\s+?(?P<eMail>.*?)\r?\n"
#StudentID := "SSN\s+?(?P<StudentID>.*?)\r?\n"
[color=#FF0080]#phone := "Home\s+\W?(?P<aCode>\d{3})\W+?(?P<ph1>\d{3})\W+?(?P<ph2>\d{4})\r?\n"[/color]
;#phone := "Home ((?P<aCode>\d{3})\W+?(?P<ph1>\d{3})\W+?(?P<ph2>\d{4})\r?\n"
Regexmatch(ONYXdata, #name, _)
Regexmatch(ONYXdata, #email, _)
Regexmatch(ONYXdata, #StudentID, _)
[color=#FF0080]Regexmatch(ONYXdata, #phone, _)[/color]
}
msgbox % "Data Captured to Vars from ONYX `n"
. "Name:`t`t`t" _fName "`n"
. "Last Name:`t`t" _lName "`n"
[color=#FF0080] . "Phone Number:`t`t(" _aCode ") " _ph1 "-" _ph2 "`n"[/color]
. "Email Address:`t`t" _eMail "`n`n"
. "Address Line 1:`t`t" address "`n"
. "Address Line 2:`t`t" address2 "`n"
. "City:`t`t" City "`n"
. "State:`t`t" State "`n"
. "Zip Code:`t`t" ZipCode "`n"
. "Student ID#: `t" _StudentID "`n`n"
Return
[color=#8000BF]; CTRL+SHIFT+0 (Zero) Test Macro for Parsing Loop
^+0::
KeyWait, 0
ONYXData=
(
Casey Allerman (ID:20442433 ~ D3 Mailer: 636049)DetailsExternal ContactsInternal ContactsOrganization ChartReportsStudent Profile
Customer Details
To search for a customer, click the search button. To add a new customer, click the add button.
Individual
Email mgalloner913@gmailer.com
Company Summit Hallsey High School
Partner Information
Partner Access
Details
Pref. Language ENG
SSN 111-22-3344
Sync with PSP
Telephone
Business (501) 555-7127
Home (501) 555-7222
Home Address
11998 Swirling Brook Ln
TEST Apt 2x
Frenchy, TX 70886-1745
)[/color]
; This section catches & stores the address first, it can tell if there are 2 or 3 address lines.
Loop, parse, ONYXdata, `n, `r
{
if inStr(A_LoopField, "Home Address")
nexlineIsAddress := 1
else if (nexlineIsAddress)
{
address := A_LoopField
nextlineMightBeAddress2 := 1
address2 := ""
nexlineIsAddress := 0
continue
}
else if RegExMatch(A_LoopField,"^(.*) ([A-Z]{2}), (\d{5})",_)
{
City := _1, State := _2, ZipCode := _3
nextlineMightBeAddress2 := 0
}
else if (nextlineMightBeAddress2)
{
_address2 := A_LoopField
nextlineMightBeAddress2 := 0
}
}
; This next section catches & stores the First Name, Last Name, ONYX email address, Student ID#, and Telephone Number.
Loop, parse, ONYXdata, `n, `r
{
#name := "Name:\s+?(?P<fName>\w+)\W+?(?P<lName>.*?)\r?\n"
#email := "Email\s+?(?P<eMail>.*?)\r?\n"
#StudentID := "SSN\s+?(?P<StudentID>.*?)\r?\n"
[color=#8000BF]#phone := "Home\s+\W?(?P<aCode>\d{3})\W+?(?P<ph1>\d{3})\W+?(?P<ph2>\d{4})\r?\n"
[/color]
Regexmatch(ONYXdata, #name, _)
Regexmatch(ONYXdata, #email, _)
Regexmatch(ONYXdata, #StudentID, _)
[color=#8000BF]Regexmatch(ONYXdata, #phone, _)[/color]
}
msgbox % "Data Captured to Vars from ONYX `n"
. "Name:`t`t`t" _fName "`n"
. "Last Name:`t`t" _lName "`n"
[color=#8000BF] . "Phone Number:`t`t(" _aCode ") " _ph1 "-" _ph2 "`n"[/color]
. "Email Address:`t`t" _eMail "`n`n"
. "Address Line 1:`t`t" address "`n"
. "Address Line 2:`t`t" address2 "`n"
. "City:`t`t" City "`n"
. "State:`t`t" State "`n"
. "Zip Code:`t`t" ZipCode "`n"
. "Student ID#: `t" _StudentID "`n`n"
Return; CRTL+SHIFT+o (o as in Oscar) MACRO#1
; CTRL+SHIFT+0 (Zero) Test Macro for Parsing Loop MACRO#2
Can anyone help me out here?








