Simplicty and flexibility!


New Sample! Emulate OpenRelated (F10) to allow search in "related" form. (Many COOL functions)

Started by DataEase
You will need to Sign In to be able to comment on the Blog!

New Sample! Emulate OpenRelated (F10) to allow search in "related" form. (Many COOL functions)

Download Sample!

WE have a lot of question about OpenRelated(F10) and why you can't break the filter and search freely in the related form.

OpenRelated() is designed to open a form with a fixed filter = relationship constraint and it is designed so the user can?t override this. It is like a hardcoded view in SQL.

You can drill down further in the selection but the original constraint is ?unbreakable?.

But…

You can of course ?emulate? the Open Related functionality.

We do that all the time. In fact we prefer not to use Open Related much because we find it very limiting.

In your short post you have included many ?bombs? and it gives us a great opportunity to showcase a lot of workarounds and functions.

Stuff we will use is:


SelectionFilter() ? hidden beauty but slightly awkward to use if you don?t know it.
StringEscape() ? built into most function but allow you to escape /? into ? and other ?illegal? characters.
SetVar()/GetVar() ? New global variable function with named functions.
Re-coding Short Cut keys via Customer Menu in this case F10.
OML GotFocus event to help us emulate F10 open active line from Subform
0 or ?? to complete an IF() function, what are the rules?
How to use a Global variable to give instructions to form to shift to TableView.
MoveObject() ? Move objects around and position them.
SetState() ? Manipulating objects (hide/show/enable/disable/click)

1. You say F10 not OpenRelated. This imply that you use the Short Cut key rather than the function, which make this much more complex ;-)

The normal way to do this is simply to put a button in the form (Open OrderLines in Tableview) ? we added a variable to switch the form to table view.


SetVar("OrderNr",OrderNr)+SetVar("Open","New")+SetVar("TableView","Yes")+DocumentOpen("OrderLines")


What we do here is basically to set the some global variables with the values we want to search for, and then we Open the document in normal mode i.e. no relationship.

When the form opens we have a virtual fields with the derivation:


If (GetVar(?Open?)=?New? and GetVar(?OrderNr?) not=blank,SetVar(?Open?,?New?)+SelectionFilter(?OrderNr=?,GetVar(?OrderNr?)),0) ? Why 0 and not ???

This derivation will fire on open or new record but it will only do anything every time it comes in with GetVar(?Open?)=?New?) which we reset to blank immediately on first fire.

We used a simplified derivation here that will basically just search up all order lines, we will later show you how to add an extra criteria.

What we have done here is basically to emulate the function OpenRelated() but in such a way that you can clear the selection filter and continue to use the form as normal…

But you asked how to do this with F10…. That takes it to a different level.

2. We need to Manipulate the F10 Shortcut.

You do this by opening the Custom Menu dialogue under Document in the toolbar:

Here we find the F10 shortcut and change it to the action:
Execute Function/Derivation and then execute the following derivation:

DocumentOpen("OrderLines")+SetVar("OrderNr",OrderNr)+SetVar("Open","New")

Ths is the same derivation that we put on the button, just without the Tableview option.

We have now manipulate F10 to behave as we want for the form Order (it will remain unchanged for other forms).

Now we need to add the special behaviour you get if you stand on an active row in the subform and hit F10. (F10 is quite special).

This we do by programming the GotFocus event on the field Description (In real life you would need to do it on each row in the subform to make it foolproof but this is demo).



This will set the global variable Item every time this row get focus i.e. when it is being the active field in the subform, it doesn?t matter if it is being clicked on by the mouse or if you tab into it.

We are now ready to hit F10.

In the order line form we add a virtual field (manip) as discussed but we now include the Item in the selectionfilter() setup.



This derivation do a lot of stuff ;-)

if (GetVar("Open")="New",SetVar("Open","") ? this make sure that we only do this once.

+if (GetVar("OrderNr") not=blank , -- do we have a selection filter at all.

SelectionFilter(concat("OrderNr=",Getvar("OrderNr"), -- we add: OrderNr=0003 ex. To the filter.

if(GetVar("Item") not=blank , -- do we have an item specified?

concat(" and Description=/'",GetVar("Item") ,"/'") ? this is fun and why Selectionfilter has not been used much in previous versions of DE. The filter is a fully formatted string, since we here search for DESCRIPTION(TEXT) we need to include?? in the string, which everyone know is difficult traditionally. In DE8 we have built in a global function called StringEscape() that will convert certain codes to reserved characters (i.e. characters that can?t be used in a derivation in dataEase (? Enter, Tab etc).

What we want to see is something like: OrderNr=00002 and Description=?Volvo V70?.

The code /? will be converted to ? when used in concat so this is what we use here: /'. We could alternatively have used chr(34) but /? can be used directly inside a string ?this is my /?name/? etc?. without the need of concatenation.


,"")),""),0),0) ? This just close the concats, selectionfilter and the if functions. See that we use ?? sometimes and 0 sometimes. This is due to the IF function. Both results need to be of the same type, so if true is TEXT, the FALS need to be TEXT. When we add up functions like we do here the result is numerical, so we need to counterbalance with a false that is numerical.

+If (GetVar("TableView") = "Yes",SetVar("TableView","")+ViewAsTable( ) ? table view? Yes. OK We reset the variable and switch to table view.
,MoveObject("Record1","C","C")) ? NO. OK then we center the record object in the form to make it look ?Pleasing? and we get to show off MoveObject.
+SetState("Manip",0) ? this simply hide the virtual field which is there just to do a job not to be seen. Remember a field need to be in the visual part of a form on open to be executed so don?t ?hide? it by putting it outside the window!



Written by DataEase 24/02/15 at 18:13:12 Dataease [{8}]FIVE
DG3_BlogList