0 Replies Latest reply on Apr 6, 2012 1:34 PM by MacDrawPro

    Applescript to change cellValue in Filemaker



      Applescript to change cellValue in Filemaker


      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:

      set target_folder to path to "cusr" as string

      set target_folder to target_folder & "Documents:Databases:"

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

      set file_name to "ASC-TestDataBase"

      set table_name to "PostFile"

      set target_database to target_folder & file_name & ".fp7"

      (* Open FileMaker target database *)

      tell application "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 *)

      set the total_num_records to the count of records

      display dialog "Total Num of Records in DB : " & (total_num_records as string)


      repeat with i from 1 to total_num_records

      tell record i

      set the this_date to (get cellValue of cell "Post Date")

      set the this_name to (get cellValue of cell "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 & " --> "}

      end tell -- record

      end repeat

      on error error_messagenumbererror_number

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

      buttons {"Quit"} default button "Quit"

      end try

      end tell --> table

      end tell --> database

      end tell --> App


      on sub_change_date(this_date)

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


      --set this_date to "Dec 23 2012"

      set my_date to {}

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

      set num_list to {"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_datethese_itemsmy_date}

      copy last item of these_items to end of my_date

      (* Replace Month with Number of Month *)

      repeat with i from 1 to the count of month_list

      if item i of month_list is item 1 of these_items then

      copy item i of num_list to end of my_date

      end if

      end repeat

      (* Copy Day to My_Date *)

      copy second item of these_items to end of my_date

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

      return my_date as string

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

      end sub_change_date