Ask Reuben

Current Folder Page

What is the current folder page? 

Why is there no method to return current folder page?

The concept of folder and page is controlled by the front-end.  The folder page that has the field with focus will be brought to the front by the front-end.  You can provide hints with the ui.Form.ensureElementVisible() method for the case when the field with focus is not in a folder or there is no focusable field (i.e. in a MENU statement), but there is no ui.Form method that explicitly sets the current folder page.

Conversely there is no ui.Form method that will return the current folder page.  If you study the AUI Tree, you will see that in the folder node, there is no attribute that stores the current folder page.  Note in this screenshot of the AUI Tree, in the list of attributes for the folder node there is no page attribute …



… Similarly for the Page node there are no attributes that say this page is the top one.  If we were to store the current folder page in the AUI Tree then this would imply an interaction with the back-end every time a user clicks on a folder page in order to update the copy of the AUI Tree in the background.  We would also have to update this value as user tabbed from a field on one page to another.

The design has been like this for 20+ years, I would not consider it likely to change any time soon.  Other information that is front-end only includes things like table column widths.  When you resize a table column width, there is no interaction with the front-end to pass the new width value to the back-end.

There is one little trick you have up your sleeve to determine what folder page is on top.  The technique is to look at the node that has the focus as determined by the focus attribute of the AUI Tree root node.  With this node, recursively look at its parent node until you get to the point where you have a “Page” node.   Once you have a page node you can check that its parent node is the Folder you are interested in, and if it is then the Page node you have, the value of its name attribute is the name of the current Folder Page.  This technique only works when the currently focusable field is in a Folder/Page, it cannot tell you what the current folder page is if the focusable field is not displayed beneath a folder.  The code below has a library function you can adapt.

Other Ask-Reuben articles on folder pages include Show Folder Page, Folder Rendering.


FUNCTION get_current_folder_page(folder_name STRING) RETURNS STRING
DEFINE focus_node om.DomNode
DEFINE focus_id INTEGER
DEFINE result STRING
    
    LET focus_id = ui.Interface.getRootNode().getAttribute("focus")
    LET focus_node = ui.Interface.getDocument().getElementById(focus_id)

    WHILE focus_node IS NOT NULL
        IF focus_node.getTagName() = "Page" THEN
            IF focus_node.getParent().getAttribute("name") = folder_name THEN
                LET result = focus_node.getAttribute("name")
                EXIT WHILE
            END IF
        END IF
        LET focus_node = focus_node.getParent()        
    END WHILE
    RETURN result
END FUNCTION