Jump to content
Server Maintenance This Week. ×

Auto Constrain


sal88

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

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 by LaRetta
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

This topic is 3472 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.