March 26, 201312 yr Not entirely sure how to explain this, but I have a layout with a portal. Most of the fields displayed in the portal are set as non-enterable while in browse mode, as the data is coming from a table that should not be edited. I have a script in the portal that needs to take the product ID from the portal and create a new record in another table, but there are times when I've noticed it creating a record for the wrong product ID. It seems that what is happening is that when I click into an editable field FileMaker properly identifies the record I am on and properly picks up the Product ID I want. However, if I just click on the button in the portal, or click on one of the fields that is not editable, the line itself highlights, but the record is not being selected, so the script runs having grabbed the Product ID from the first row of the portal, instead of the row I clicked. I don't want to require the user to click into an editable field before running the script, but I can't figure out how else to get the portal to know which row the script is supposed to run from. Help?
March 27, 201312 yr Solution You need to create focus on the portal record you are trying to capture by making it active before grabbing the Product ID. You can see your mouse click highlights the record you are clicking on. That means Filemaker knows which record you intend. Now you just need to make it active. You can do that in your script a number of ways. An easy way is to use a GoToField (any field in that record) before grabbing the Product ID. You need to do that near the start of the script while Filemaker is still aware of the record you've targeted. Levi -- Laura (Levi) Vie Lead Programmer/Account Manager Filemaker 11 Certified Programmer Filemaker 10 Certified Programmer Filemaker 9 Certified Programmer Filemaker 8 Certified Programmer EXCELISYS - http://www.excelisys.com E: [email protected] V: 573-874-5176 - FBA Member - FileMaker 7/8/9/10/11/12 Certified Developers & Consultants - Designers and Developers of the FileMaker Business Tracker
March 27, 201312 yr Why not pass the product ID into the script attached to the button via a parameter which is passed when the button is clicked? Brian
March 27, 201312 yr Author You need to create focus on the portal record you are trying to capture by making it active before grabbing the Product ID. You can see your mouse click highlights the record you are clicking on. That means Filemaker knows which record you intend. Now you just need to make it active. You can do that in your script a number of ways. An easy way is to use a GoToField (any field in that record) before grabbing the Product ID. You need to do that near the start of the script while Filemaker is still aware of the record you've targeted. Levi Thanks, that fixed it. Found a couple problems as I looked closer at the script, but this fixed the main issue. I will not be able to control the users as well as I'd like in this particular spot (they can add a product in the portal, and I can't be certain that they've committed the data before they click to run the script I'm calling), so I had put a Commit Records script step at the beginning of the script. I changed that so the first thing I'm doing is moving to a field and grabbing the product ID before I commit the record, and that fixes it. (Well, after I fixed another logic error I had in a subscript.) Thanks for your assistance! Why not pass the product ID into the script attached to the button via a parameter which is passed when the button is clicked? Brian This probably would have worked better, except my script is a bit scary right now doing too many things. Had I thought this through before writing it, I would have broken it down into 2-4 subscripts that would have made this much easier (and I could have handled it all via script parameters), but as I now have it working, I don't want to go back and clean it up. I'll probably regret that decision next spring when I have to dig out this database again. ...or next week if something else breaks and I end up rewriting the script anyway.
March 28, 201312 yr Glad to help. As you said this might not be the most efficient or bulletproof answer, but it will get the job done.
Create an account or sign in to comment