In my OK (Save) Button I have some embed code to check field values and if wrong I want to cancel the OK (Save) from writing the record and would then like to SELECT(?WrongField) and stay on the form.
Move your code from the Ok button to the WindowManagerClass.TakeCompleted method before parent call.
Return an appropriate value after reading the docs for the method.
Ont tiny thing to add to what totalhip said. in ThisWindow.TakeCompleted, before the parent call, you can CYCLE to let the method handle returning LEVEL:Notify which is what you want. Or you can just RETURN LEVEL:Notify yourself. I like using CYCLE because I think it’s neater but it’s personal preference.
I don’t think it is good coding practice to RETURN from inside a LOOP but the embed points for ThisWindow.TakeCompleted (and lots of others), are inside a LOOP. Using CYCLE causes the code to issue its own RETURN LEVEL:Notify from inside the loop but I can pretend that at least I am not doing it. If I were coding WindowManager.TakeCompleted, I would have done without the loop or used a flag field (as they used Looped) to indicate success or failure of the code. Then in the embed, I could set the flag the way I wanted and issued a BREAK then tested the value of my flag below the loop to determine what value to RETURN. I am just picky and in your case, issuing RETURN LEVEL:Notify directly is really equivalent to CYCLE.
Thank you very much for the detailed explanation.
I now understand this Embed a lot better.
I will be going with your suggestion and use CYCLE.
PS: I wished I knew about this Embed long time ago then much of my code would have been better, but this is how we learn.
This embed is going to solve a lot of my problems.
Have lots of forms where I will be implementing this.
If you try to lose the “which embed” mentality and look at what the underlying code does, it will greatly enhance your understanding of what’s going on, not to mention your productivity. I find it useful to open up the source classes and see what calls what. (I use Ctrl+F a lot)
ABC can definitely seem like voodoo at first, which makes stuff feel unattainable, but it’s really not so bad.
Another reason to use the TakeCompleted method embeds is that the TakeAccepted embed for the ?Ok button is not fired if the user closes the window then opts to save when prompted by the ABC class. The TakeCompleted method, however, does.
On forms, I use the embed BEFORE the parent call to check that the user has completed things properly and to set some hidden fields that must be set based on the main file fields.
I use the embed AFTER the parent call to test IF ReturnValue = LEVEL:Benign then do any child or related record processing based on changes to the form’s primary file.
More related question. I need to complete a Form (so user clicked on OK, save everything) but not close current window but remain on it like I open window again. How I can easy do this?
SaveButton control can still work. You can hide the button when needed or hide it always and just POST an event:accepted to it when needed. I do that in one of my procedures and it works well. Note that takeCompleted is call when the button fires.