March 7, 20223 yr I have a script called "generate 100 records" in a FM 13 table called qrgen that is supposed to run another script called "new record" which creates a new record then generates a QR code using the Google API. The script is supposed to run for 100 iterations but it doesn't stop at 100. I found this FM 12 example which I would assume should work in FM 13 (the first example): https://fmhelp.filemaker.com/help/12/fmp/en/html/create_script.13.32.html Here's my script: Loop perform script ["new record"] set field [qrgen::counter; qrgen::counter+1] Exit loop if[qrgen::counter>100] End loop I cannot figure out why the loop continues past 100. Any ideas would be appreciated. PS: I've posted a version of the file here if you'd like to see it: www.blue-iceberg.com/files/qrcode.fmp12 Edited March 7, 20223 yr by rcacciato
March 7, 20223 yr Why not attach the file here, it's much more convenient. From what I see, the counter field is not a global field - so instead of being increased at each iteration, each record gets a value of 1. I am also puzzled why you're not using a variable as the counter instead of a field. The example you refer to seems very ancient. Note also that you're not following it correctly: if you want to use a field as the counter, then the field (which must be a global field) needs to be reset to 0 (or empty) at the beginning or at the end. Yet another reason to use a script variable (prefixed by a single $) which expires when the script has run out.
March 7, 20223 yr Author Ah, right. Thanks for revealing the mystery... let's say it's been a long time. I didn't know about script variables--I learned FM a century ago. How does one use a script variable? I changed counter to a global field and it worked. Then I made another change and now it doesn't... Argh. Attaching the file here as you suggest. Thanks so much! qrcode.fmp12
March 7, 20223 yr Author OK scratch that, I got the counter to work. But I don't know about script variables. How does one use a script variable? Thanks.
March 7, 20223 yr 35 minutes ago, rcacciato said: How does one use a script variable? Try it this way: Go to Layout [ “qrgen” (qrgen) ] Loop Set Variable [ $i; Value:$i + 1 ] Exit Loop If [ $i > 100 ] Perform Script [ “new record” ] End Loop
March 7, 20223 yr Author Wow. Simple and elegant. Thanks for explaining this, you've been a huge help!
Create an account or sign in to comment