13 Replies Latest reply on Dec 12, 2016 3:35 PM by SteveMartino

    detecting modal dialog?

    everyman

      Is there a way to detect whether a window is a modal dialog or not?  There doesn't appear to be a get-able window attribute for that.

        • 1. Re: detecting modal dialog?
          David Moyer

          Hi,

          I don't know of any functions either.  There may be some tricky way of testing against the rules of the modal window, but that seems sort of backwards.

          Since the programmer creates the modal window, he/she should be able to know what it is.  A simple way (to not keep track) would be to come up with a window naming convention you could test against.  A simple not-so-pretty example would be to preface all modal window names with an underscore ... $windowName = "_Required User Input"

          • 2. Re: detecting modal dialog?
            philmodjunk

            I'm curious as to why you would need this.

             

            You can only have one modal window open and the user will be blocked from interacting with any other windows until the modal window is closed so this would not seem hard to keep track of.

            • 3. Re: detecting modal dialog?
              everyman


              philmodjunk wrote:

               

              I'm curious as to why you would need this.

               

              You can only have one modal window open and the user will be blocked from interacting with any other windows until the modal window is closed so this would not seem hard to keep track of.

              Sometimes it's preferable to open a new (off-screen) window to process certain requests instead of using Freeze Window.  I've just run into a situation where a script might be called from the main window or from a modal dialog.  In the latter case Freeze Window is the only option, and it would be nice to detect the modal dialog before an error is generated (or before Close Window closes, er, the wrong window).

              • 4. Re: detecting modal dialog?
                philmodjunk

                Yes, but since there is only one such window, this should be easy to keep track of.

                 

                For example, each time your script opens a modal window include this script step:

                 

                Set Variable [$$ModalWindow ; value: Get ( windowName ) ]

                 

                Then use the onWindowClose trigger to perform a script that does this:

                 

                If [ $$ModalWindow = Get ( WindowName ) ]

                   Set Variable [$$ModalWindow ; Value: "" ]
                End If

                 

                 

                Then any script that might be affected by a modal window being open can check the $$ModalWindow variable to see if a window is open or not.

                 

                (These days, I find that I frequently avoid this issue by using a popover or a floating document window instead of a modal window...)

                • 5. Re: detecting modal dialog?
                  SteveMartino

                  Get(WindowStyle) returns 2 for modal.

                  2 of 2 people found this helpful
                  • 6. Re: detecting modal dialog?
                    David Moyer

                    Doh! - I looked but didn't "see" it.  Thanks Steve.

                    • 7. Re: detecting modal dialog?
                      philmodjunk

                      Thanks Steve, but you'd need to test every open window for that. Might be easier in some cases to use a global variable set up for tracking the name of any modal window currently open as you don't have to cycle thru a list of windows to see if any are modal...

                      • 8. Re: detecting modal dialog?
                        everyman

                        philmodjunk wrote:

                         

                        Thanks Steve, but you'd need to test every open window for that. Might be easier in some cases to use a global variable set up for tracking the name of any modal window currently open as you don't have to cycle thru a list of windows to see if any are modal...

                         

                        The sound you all heard was the self-administered dope-slap.  I was looking at Get (WindowMode) and failed to look a little farther down-list.

                         

                        The script runs in the context of the frontmost window which will either be modal or not.  Put another way: once you've opened a modal dialog, Get (WindowStyle) will always return 2 because you can't select another window until the modal dialog is closed.

                        • 9. Re: detecting modal dialog?
                          David Moyer

                          To reinforce some bits from above, I'm unable to create additional windows (in a script) after opening a modal window.  In this script, the window "temp" is not created (and as noted before, step 5 shows a Windows Style of 2.).

                          • 10. Re: detecting modal dialog?
                            David Moyer

                            testing again, it appears that one can open multiple modal windows ...

                            • 11. Re: detecting modal dialog?
                              everyman

                              David Moyer wrote:

                               

                              To reinforce some bits from above, I'm unable to create additional windows (in a script) after opening a modal window. In this script, the window "temp" is not created (and as noted before, step 5 shows a Windows Style of 2.).

                              Exactly.  My test (before my last post) was a similarly brief script:

                              Screen Shot 2016-12-12 at 6.22.32 PM.jpg

                              When the new window is modal, the script can't switch back to the other window and the error pops up.

                              • 12. Re: detecting modal dialog?
                                everyman

                                David Moyer wrote:

                                 

                                testing again, it appears that one can open multiple modal windows ...

                                Yes.  In the instant case I was trying to open a document window from a modal dialog, which isn't allowed.

                                • 13. Re: detecting modal dialog?
                                  SteveMartino

                                  Yeah I ran into trouble with that when I would have a modal, then open another modal-for example going to a related record, then opening up a picker window.

                                  During testing, I would change the script to make it not a modal, so I could edit the layout for size or moving fields, while testing.  Was a real head scratcher to try to figure out what was going wrong.  So I only make them all modal when needed after I'm fully done testing.