Create Record and fields from Applescript list

Hi!

I have a script that is scraping an internal webpage for contact information including email, phone, last name, and full name. So far it is in a list format {“email”, “phone”, “last”, “first”}.

My goal is to create a new FileMaker record for each new contact and populate fields for email, phone, last and first names. Since theres multiple contacts all in the one AS list I’m not quite sure how to do it.

I found some code that will create new records for everything in the list but I’m not sure how to indicate the parts I want as fields. Any help is much appreciated!


--try
tell application "Safari"
	set pageHTML to source of document 1
end tell

set TID to AppleScript's text item delimiters -- save previous value
set theList to {}
------- Find Email Address ----------
considering case
	set text item delimiters to "Email Address :
														</TD>
													</TR>
													
													<TR>
														<TD style=\"padding:3px\">
															"
	set emaila to text items 2 thru -1 of pageHTML
end considering

set text item delimiters to " "
------- Find Phone Number ----------
set text item delimiters to "Primary Phone :
														</TD>
													</TR>
													
													<TR>
														<TD style=\"padding:3px\">
															"
set phonen to text items 2 thru -1 of pageHTML
set text item delimiters to " "
------- Find Last Name ----------
set text item delimiters to "Last Name :
														</TD>
													</TR>
													
													<TR>
														<TD style=\"padding:3px\">
															"

set lname to text items 2 thru -1 of pageHTML
set text item delimiters to " "
------- Find First Name ----------

set text item delimiters to "First Name :
														</TD>
													</TR>
													
													<TR>
														<TD style=\"padding:3px\">
															"

set fname to text items 2 thru -1 of pageHTML
set text item delimiters to " "


repeat with i from 1 to count of emaila
	set end of theList to text item 1 of (item i of emaila)
	set end of theList to text item 1 of (item i of phonen)
	set end of theList to text item 1 of (item i of lname)
	set end of theList to text item 1 of (item i of fname)
end repeat

set text item delimiters to TID
return theList
--end try

tell application "FileMaker Pro Advanced"
	tell document "myDocument"
		show layout "DataManipulationLayout"
		tell table "data"
			repeat with theList in theList
				create a new record with data theList
			end repeat
		end tell
	end tell
end tell


You can create parallel lists rather than 1 list. Then select item 1 , 2, 3 etc from each list for your import statement.

set emailaList to {}
set lnameList to {}
set fnameList to {}
set phonenList to {}

repeat with i from 1 to count of emaila
set end of emailaList to text item 1 of (item i of emaila)
set end of phonenList to text item 1 of (item i of phonen)
set end of lnameList to text item 1 of (item i of lname)
set end of fnameList to text item 1 of (item i of fname)
end repeat

Thanks again adayzdone-

Here is how I got it to work:


tell application "Safari"
	set pageHTML to source of document 1
end tell

set TID to AppleScript's text item delimiters -- save previous value

------- Find Email Address ----------
set emailaList to {}
considering case
	set text item delimiters to "Email Address :
														</TD>
													</TR>
													
													<TR>
														<TD style=\"padding:3px\">
															"
	set emaila to text items 2 thru -1 of pageHTML
	set emailaList to {}
end considering

set text item delimiters to " "
------- Find Phone Number ----------
set phonenList to {}
set text item delimiters to "Primary Phone :
														</TD>
													</TR>
													
													<TR>
														<TD style=\"padding:3px\">
															"
set phonen to text items 2 thru -1 of pageHTML
set text item delimiters to " "
------- Find Last Name ----------
set lnameList to {}
set text item delimiters to "Last Name :
														</TD>
													</TR>
													
													<TR>
														<TD style=\"padding:3px\">
															"

set lname to text items 2 thru -1 of pageHTML
set text item delimiters to " "

------- Find First Name ----------
set fnameList to {}

set text item delimiters to "First Name :
														</TD>
													</TR>
													
													<TR>
														<TD style=\"padding:3px\">
															"

set fname to text items 2 thru -1 of pageHTML
set text item delimiters to " "


repeat with i from 1 to count of emaila
	set end of emailaList to text item 1 of (item i of emaila)
	set end of phonenList to text item 1 of (item i of phonen)
	set end of lnameList to text item 1 of (item i of lname)
	set end of fnameList to text item 1 of (item i of fname)
end repeat

set text item delimiters to TID
set recno to 0
tell application "FileMaker Pro Advanced"
	tell document "myDocument"
		show layout "DataManipulationLayout"
		tell table "data"
			repeat with i from 1 to count of emaila
				set recno to recno + 1
				create record
				tell last record
					set cell "Email" to text item recno of emailaList
					set cell "Phone" to text item recno of phonenList
					set cell "LastN" to text item recno of lnameList
					set cell "FirstN" to text item recno of fnameList
				end tell
				
			end repeat
			
		end tell
	end tell
end tell



Nice :slight_smile:

Why

set recno to 0
set recno to recno + 1
set cell "Email" to text item recno of emailaList

and not …

set cell "Email" to text item i of emailaList

Yes that is more elegant. Thanks