sal88 Posted September 16, 2014 Posted September 16, 2014 Hi all Struggling to find an elegant way of doing this, I think script triggers might do the job but no luck finding a solution. I would like certain layouts to always apply a constrain function after a find request is made but also after the show all records command is executed. Is this possible? Thx
Lee Smith Posted September 17, 2014 Posted September 17, 2014 If you show all records, then that is what you will get. are you following the steps in the help http://fmhelp.filemaker.com/fmphelp_13/en/html/find_sort.5.17.html
LaRetta Posted September 17, 2014 Posted September 17, 2014 I would like certain layouts to always apply a constrain function after a find request is made but also after the show all records command is executed. It sounds important. Have you considered using security to restrict the record sets to this 'constrained' criteria? What about if User executes a 'show omitted'? Can you explain the purpose of this constrain? A trigger can fire on leaving find mode but it sounds like you need more than that.
Rick Whitelaw Posted September 17, 2014 Posted September 17, 2014 Reacting to your description of the problem literally, I would say the answer is no.
sal88 Posted September 17, 2014 Author Posted September 17, 2014 Hi all Thanks for your responses. The purpose of the constrain is that the user will not see the records that do not belong to that layout. The table in question has multiple entities: Items, Labour, Recurring Services. As they are all to be displayed on an invoice I have decided to keep them all in the same table (as per advice). For a more intuitive user experience I have separate layouts for each entity, but with each pointing to the same table. Each record has a 'type' field that determines whether it is an item, labour or RS. The problem with using security is that the 'hidden' records will still appear, but will just say <no access> - at least on the 'show all' command, unless I'm doing something wrong. Would look a bit neater if those records were not displayed at all. The main thing that spurred this query was realising that users may want to use the 'omit' option on search requests. This would throw off my usual method of search restrictions which merely consisted of a find script, which enters find mode, with specified criteria (in order to hide records that need to be hidden), pauses, allows the user to put in their own criteria and then hit enter to perform the query. Of course if they select omit in one of their requests it will not produce the desired effect. To deal with that I have now altered the script so that at the end, a constrain with the appropriate 'type' criteria applied, rather than specifying the criteria before the find request is executed. I hadn't thought of what would happen if the user chose to 'show omitted'. But I don't see that function being required. At the moment I have the following: Toolbar locked (no shortcut keys) Search button on layout performs script as above, user able to create omit/include search requests. Constrain automatically performed afterwards as per script. Show all button on layout basically performs the constrain step that the search script uses. I think that's probably the best I can hope for. It would be nice to have a solid 'constrain always' script trigger that performs after all find requests and show alls, or something along those lines. It would mean I could unlock the toolbar and give the user a bit more freedom with querying data, e.g. they could actually use 'show omitted'. They could also use keyboard shortcuts, and there would be less scripting. What do you think?
LaRetta Posted September 18, 2014 Posted September 18, 2014 (edited) Hi Sal88, Tight control (providing your own find console and options), and constraining after their find sounds best. I do not know how your users are working with the data but another option is to use a viewer table with global values (that you control or them) and provide the records in a portal. If the User should absolutely never have access to other Types then security is important but it will not eliminate incorrect-type records with Show All Records, as you know. I might have other suggestions if I knew more about your solution but I currently do not have time to devote to a more in-depth review. In all, it seems you have it under control and maybe others have suggestions as well. Edited September 18, 2014 by LaRetta
Rick Whitelaw Posted September 19, 2014 Posted September 19, 2014 I think I misunderstood the original question. You aren't asking if this can be done automatically upon loading a layout, are you?
sal88 Posted September 23, 2014 Author Posted September 23, 2014 Not nescessarily upon loading a layout, but just after any search query is made (including show all). I will stick to my current set up as per LaRetta's advice. Thanks for you help guys
David Jondreau Posted September 23, 2014 Posted September 23, 2014 You'll need to add that Constrain[] in a couple places. 1) You'll need an OnModeExit triggered script that 1) Checks to see if a flag is set and exits if it is 2) Checks to see what mode is being exited, and if not Find, exits 3) Sets a flag, then constrains the found set, then clears the flag. The flag is to prevent the script from looping since the Constrain[] will trigger on ModeExit as well. 2) You'll need a script to override the default behavior on the Show All command using Custom Menus (using FM Pro Advanced). That script would be similar to the OnModeExit script above. You'll also need to add that script to the "Show Omitted Only" menu command too.
serzone Posted November 7, 2014 Posted November 7, 2014 You'll need to add that Constrain[] in a couple places. 1) You'll need an OnModeExit triggered script that 1) Checks to see if a flag is set and exits if it is 2) Checks to see what mode is being exited, and if not Find, exits 3) Sets a flag, then constrains the found set, then clears the flag. The flag is to prevent the script from looping since the Constrain[] will trigger on ModeExit as well. 2) You'll need a script to override the default behavior on the Show All command using Custom Menus (using FM Pro Advanced). That script would be similar to the OnModeExit script above. You'll also need to add that script to the "Show Omitted Only" menu command too. Thank you! That's the best way to "auto" constrain. Here's the script I'm using. It might come in handy to others. What I'm trying to do is allow someone to run a find like they normally would but then, right after their search, constrain the found set to just "their" records. 1. On the layout set a script trigger: OnModeExit, enable it just for Find. The way this works is: the moment the user hits the enter key or the find button to run their search this script will fire FIRST. Again, be careful, your script will fire FIRST, BEFORE their actual search happens AND before they get into Browse mode. 2. The script: If [ SESSION::z_ConstrainFlag = 1 ] // if the flag is set, exit to prevent infinite loop Exit Script [ Result: True ] Else Perform Find [ ] // this will basically allow the user's intended search to run and give them their set Set Field [ SESSION::z_ConstrainFlag; 1 ] // set the flag Enter Find Mode [ ] // start running the constrain search Set Field [ YourField::Here; "YourValueHere" ] Constrain Found Set [ ] // constrain - this will cause this very script to fire again since you are going from find mode to browse mode but it will die because the flag is set Set Field [ SESSION::z_ConstrainFlag; "" ] // now you can clear the flag. End If Many great thanks to David.
Recommended Posts
This topic is 3669 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 accountSign in
Already have an account? Sign in here.
Sign In Now