Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3861 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hello All.   I am trying to write a script (in FMPro 12) with a Loop which does the following steps:

 

(1) copy the content of a textfield in the current record called "code_text"

(2) Go to the next Record

(3) Check if a textfield called "matches" contains text  "yes"; only if it does, do step (4)

(4) Paste that content into a field called "accumulated_code_texts" in such a way that any existing content is added to (and not overwritten)

(5) go back to step (1)

 

Can any kind person please give me the script steps to achieve this.    Thank you.

 

Posted

Copy and paste is for the users; as a developer, you should be using the Set Variable and Set Field script steps instead. Try something like (untested):

Go to Record [ First ]
Loop
  Set Variable [ $code ; YourTable::code_text ]
  Go to Record [Next; Exit after last ]
  If [ YourTable::matches = "yes" ]
    Set Field [ YourTable::accumulated_code_texts ; YourTable::accumulated_code_texts & $code ]
  End If
End Loop

You will probably want to add some kind of a delimiter between the accumulated values.

Posted

Hi comment

 

Using what you said I was able to get the script doing what I wanted. Many thanks for this.   Philip

Posted

Hello again comment

 

Using your advice I have been able to construct a script that does (so far!) what I want.

 

The following is a part of the script, with a line which uses "Export Field Contents". It works, but as you warned me in another message, it saves the file as UTF-16, and when I upload the file to my webserver to be used as HTML I have to first convert it to UTF-8 or it won't display properly.

 

script_section2.jpeg

 

Can you tell me how I can most easily change this section of script to get UTF-8 output?

 

Many thanks.    Philip

 

 

Posted

One way to do this is to create a found set of a single record, then export records as tab-delimited with only the single field in the field export order. This is a global field, correct? So it doesn't really matter which record you choose, just do something like:

 

Show All Records

Omit Record

Show Omitted Only

Export Records

Posted

Hi comment

 

The field to be exported is not a global field, and using "found set of a single record" method would cause me problems with the sequence of other script-steps around the fragment I showed you.

 

So I looked at the thought of converting the file after its creation, and used Applescript-recording to capture such a sequence in the text-editor I'm using TextWrangler, and got the following:

 

tell application "TextWrangler"

activate

open {file "Macintosh HD:Users:philip:Desktop:gs4UPLOADS:SB_Gfiles:G002113"} with LF translation

select text 1 of project window 1

set properties of text document 1 to {encoding:8.09004642E+8}

save text document 1

close text document 1 saving no

end tell

 

If I put this into a step in my FMPro script (immediately after the "Export Field Contents" step) as "Perform Applescript" with the above in the "Native Applescript" dialog, it works for the file (G002113). But if I put it into a "Calculated Applescript" with before each " as follows:

 

"tell application "TextWrangler"
activate
open {file "Macintosh HD:Users:philip:Desktop:gs4UPLOADS:SB_Gfiles:G002113"} with LF translation
select text 1 of project window 1
set properties of text document 1 to {encoding:8.09004642E+8}
save text document 1
close text document 1 saving no
end tell"

 

it gives the FilemakerPro error dialog: "Expected end of line but found command name. (OK)" and "Unknown Error: -2741. (OK)"

 

[i was intending if this worked to replace G002113 with the $Gfile_name variable in the Calculation]

 

Can you help me with getting this to work?    Many thanks.    Philip

Posted

The field to be exported is not a global field

 

Hm. I thought you were "accumulating" values from different records in the found set - so how come the field is not global? In any case, when you export field contents, you are exporting the contents of the field in the current record only - so it should be only a matter of isolating the correct record.

 

I am also not sure why this would cause"problems with the sequence of other script-steps around the fragment I showed you." If you wish to preserve the current found set, do the export in a new window, then close the window to return to the routine in progress.

Posted

Hi comment.  No, the values being "accumulated" are from one record to the next.

 

I am attaching the database as a zip archive hoping this helps you understand the methods I am using, although I accept you will regard them as unorthodox and amateurish [rueful smile].

 

Remember, this is a single-table simple database to be used:

-- only by me on my own Mac

-- and its purpose is to manipulate text-files received from another source, save them as html on my Mac, so I can upload to my website

 

Do you have any thoughts on why the "Calculated Applescript" fails but the "Native Applescript" works?

 

Many thanks for your help so far.   Philip

myDatabase.fmp12.zip

Posted

Sorry, I cannot open .fmp12 files ATM.

 

 

Re AppleScript, it wouldn't be my first (or even second) choice to solve this problem. In general, if a native AppleScript works, but the calculated version fails, then the calculation does not produce the required script. This should be easy to test by defining a calculation field with the same formula and observing the result, resp. running the result in Script Editor to see where the error is.

  • Like 1
Posted

Do you have any thoughts on why the "Calculated Applescript" fails but the "Native Applescript" works?

 

Probably a quotes problem. Debugging AppleScripts is easier if you calculate the code within a variable whose result you can test in the AppleScript Editor.

 

Try this in your Filemaker script:

 

Set Variable [ $AS ;

List (
"set myFile to ((path to desktop) & " & Quote ( "gs4UPLOADS:SB_Gfiles:" & $yourFileNameReferenceIncludingASuffix ) & ") as text"
"tell application " & Quote ( "TextWrangler" )
  ; "activate"
  ; "open myFile with LF translation"
  ; "tell document 1"
    ; "set encoding to " & Quote ( "Unicode (UTF-8)" )
    ; "close saving yes"
  ; "end tell"
; "end tell"
) ]
Perform AppleScript [ $AS ]
Posted

Sorry, I cannot open .fmp12 files ATM.

 

 

Re AppleScript, it wouldn't be my first (or even second) choice to solve this problem. In general, if a native AppleScript works, but the calculated version fails, then the calculation does not produce the required script. This should be easy to test by defining a calculation field with the same formula and observing the result, resp. running the result in Script Editor to see where the error is.

Thanks for your help, comment.  I think I can see a way round this problem, and I very much appreciate your support.  Regards, Philip

Posted
List (
"set myFile to ((path to desktop) & " & Quote ( "gs4UPLOADS:SB_Gfiles:" & $yourFileNameReferenceIncludingASuffix ) & ") as text"
"tell application " & Quote ( "TextWrangler" )
  ; "activate"
  ; "open myFile with LF translation"
  ; "tell document 1"
    ; "set encoding to " & Quote ( "Unicode (UTF-8)" )
    ; "close saving yes"
  ; "end tell"
; "end tell"
)

 

Oh God, not yet another subscriber to Satan's convention...

 

I assure you, the semicolon belongs at the end of a line, not at the beginning!

  • Like 1

This topic is 3861 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.