1 Reply Latest reply on Apr 6, 2012 2:53 PM by philmodjunk

    Applescript to make changes in FileMaker database.



      Applescript to make changes in FileMaker database.


      Maybe someone can give me some guidance of this error I have.

      I have written an Applescript that opens a database, and table and then it goes to each record and gets the value of a cell, which is a date in the format "Jul 23 2012".  The script then accesses a subroutine to change the format of the date to be "2012-07-23".  However, when I try to access the subroutine I get an error -1708.  As a matter of fact I cannot access a subroutine, it inmediatelly gives me a error -1708.

      Don't know what I am doing wrong.  Thanks. 

      Here is the code:

      settarget_foldertopath to "cusr" asstring

      settarget_foldertotarget_folder & "Documents:Databases:"

      (* Enter the name of the database in file_name, it assumes the table has the same name *)

      setfile_nameto "ASC-TestDataBase"

      settable_nameto "PostFile"

      set target_database to target_folder & file_name & ".fp7"

      (* Open FileMaker target database *)

      tellapplication "FileMaker Pro"


      delay 0.5

      open (target_database as alias)

      tell databasefile_name

      --window 1 -- This works when the database is Open

      tell tabletable_name

      (* Count the number of records in Table *)


      display dialog "Total Num of Records in DB : " & (total_num_recordsasstring)


      repeatwithifrom 1 tototal_num_records


      setthethis_dateto (getcellValueofcell "Post Date")

      setthethis_nameto (getcellValueofcell "Name")

      copy this_date to old_date

      --Calling a subroutine creates an error

      set this_new_date to sub_change_date(old_date)

      log {i & " : " & this_name & " - " & this_date & " --> "}

      endtell-- record


      on error error_messagenumbererror_number

      display dialog "Error was triggered: No.: " & error_number ¬

      buttons {"Quit"} default button "Quit"


      endtell--> table

      end tell --> database

      endtell--> App


      on sub_change_date(this_date)

      (* Change "Jan 23 2012" to "2012-01-23" *)


      --set this_date to "Dec 23 2012"

      setmy_dateto {}

      setmonth_listto {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}

      setnum_listto {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}

      --count items of result

      set AppleScript's text item delimiters to space

      set these_items to text items of this_date

      log {this_date, these_items, my_date}


      (* Replace Month with Number of Month *)

      repeatwithifrom 1 tothecountofmonth_list

      ifitemiofmonth_listisitem 1 ofthese_itemsthen




      (* Copy Day to My_Date *)


      set AppleScript's text item delimiters to {"-"}


      set AppleScript's text item delimiters to {""}

      end sub_change_date