Dynamic Queries + Static Queries

Hi everyone,

I have wandering, once you do the whole code for a dynamic browser, can the static query that was previously assigned to the browser be used?

I have a lookup screen. Upon loading the screen, it displays all the employee using the standard AppBuilder Browser Query Builder. Once they hit a button, i get a refine search screen that add some clauses to the where (at that time, the query becomes dynamic and the browser as well). BUT, there is a "refresh button" that is used to clear all the different refine inputs. This calls a procedure that blanks &SEARCH-KEY and then re-open the query with the following:

Code:
&SCOPED-DEFINE SORTBY-PHRASE {&BY1}
{&OPEN-QUERY-{&BROWSE-NAME}}

Unfortunatly, it doesn't work anymore! It does clear everything nor does it re-open's the query!

Whey i MESSAGE the {&OPEN-QUERY-{&BROWSE-NAME}} it shows me the proper OPEN QUERY string.

Any reason why? Is it linked to the fact that the browser and or Query are now dynamic?
 
Never used a static query object in a dynamic browse object.

But - the browse object has an attribute QUERY, which must be the handle to the query object, be it static or dynamic. You need to grab the handle to the static query object and assign the browse widget's QUERY attribute to it.

ASSIGN hMyQuery = QUERY myQueryName:HANDLE.


Heavy Regards, RealHeavyDude.
 
HUm...
Not sure i get your answer :P
hehehe Might still be sleeping.

Anyway, i am using the standard query (therefore called br_table).

My current dynamic code that messes out everything is this Procedure:

Code:
/*------------------------------------------------------------------------------
  Purpose:     
  Parameters:  <none>
  Notes:       
------------------------------------------------------------------------------*/
DEFINE INPUT PARAMETER wQuery AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER cSort-By AS CHAR NO-UNDO.

DEFINE VARIABLE hBrowse AS HANDLE NO-UNDO.
DEFINE VARIABLE ghQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hnss-employee   AS HANDLE NO-UNDO.
DEFINE VARIABLE hnss-employment AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE cFieldList AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFieldName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iField AS INTEGER NO-UNDO.
DEFINE VARIABLE lOkay AS LOGICAL NO-UNDO.

MESSAGE wQuery SKIP
      VIEW-AS ALERT-BOX INFO BUTTONS OK.
  

  /* Assign the variables we need later */
  ASSIGN hBrowse = BROWSE {&BROWSE-NAME}:HANDLE
         hnss-employee = BUFFER nss-employee:HANDLE
         hnss-employment = BUFFER nss-employment:HANDLE
         cFieldList = '{&FIELDS-IN-QUERY-{&BROWSE-NAME}}'. /* Pre-Processor containing the fields */

  /* Eventually clean-up the dynamic query */
  IF VALID-HANDLE ( ghQuery ) THEN DO:
     IF ghQuery:IS-OPEN THEN
        ghQuery:QUERY-CLOSE ( ).
     DELETE OBJECT ghQuery.
     ASSIGN ghQuery = ?.
  END.

  /* Create the dynamic query */
  CREATE QUERY ghQuery.
  IF cValue[9] <> "":U THEN
     ghQuery:SET-BUFFERS ( hnss-employment, hnss-employee).
  ELSE 
     ghQuery:SET-BUFFERS ( hnss-employee ).

  ASSIGN lOkay = ghQuery:QUERY-PREPARE ( wQuery ).

  IF lOkay THEN DO:

      /* Close the query that is currently attached to the browse widget when it is valid */
      ASSIGN hQuery = hBrowse:QUERY.
      IF VALID-HANDLE ( hQuery ) THEN
      hQuery:QUERY-CLOSE ( ).

      /* Switch the queries */
      ASSIGN hBrowse:QUERY = ?.
      ASSIGN hBrowse:QUERY = ghQuery.

      /* Need to set the expandable attribute of the browse to FALSE, otherwise the first added column will fill the widget */
      ASSIGN hBrowse:EXPANDABLE = FALSE.

      /* Populate the browse widget with the fields as they were */
      DO iField = 1 TO NUM-ENTRIES ( cFieldList, ' ':U /* List is seperated by blanks */ ):
      /* Extract the field and table names from the list */

      ASSIGN cFieldName = ENTRY ( 2, ENTRY ( iField, cFieldList, ' ':U ), '.':U )
             cTableName = ENTRY ( 1, ENTRY ( iField, cFieldList, ' ':U ), '.':U ).
      /* Grab the handle to the buffer field from the corresponding buffer */
      IF cTableName = 'nss-employee':U THEN
         ASSIGN hField = hnss-employee:BUFFER-FIELD ( cFieldName ).

      /* Now add the field to the browse widget */
      IF VALID-HANDLE ( hField ) THEN 
         hBrowse:ADD-LIKE-COLUMN ( hField ).
      RUN SetColumn (INPUT iField, INPUT hBrowse, INPUT cSort-by).  /* Set the column's header color and form */
      RUN RefreshCondition (INPUT cIndex). /* Set the condition box with the proper information */
    END.
    /* Open the query */
    ASSIGN hBrowse:EXPANDABLE = TRUE
           hQuery = QUERY ghQuery:HANDLE.
    ghQuery:QUERY-OPEN ( ).
 END.
    APPLY "VALUE-CHANGED":U TO BROWSE {&BROWSE-NAME}.
    &IF lookup("FlnKey":U, "{&ENABLED-OBJECTS}", " ":U) > 0 &THEN
       APPLY "END-SEARCH":U    TO BROWSE {&BROWSE-NAME}.
    &ENDIF
END PROCEDURE.

On the initial run, the Browser is displayed properly. But as soon as i add the Refined conditions, and try to "refresh" my query to remove them, then it's impossible. Nothing happens.

I have read the line and tried to use it but can't manage to get it to work.
 
Bottom line from my point of view: You cannot mix and match static and dynamic queries with the same browse widget the way you intend to.

As soon as the dynamic query is attached to the browse widget you leave the static query in limbo. You cannot just reopen it and expect it to populate the browse widget. You need to close the dynamic query, prepare it and open it again. While we're at it, you don't need to add the columns each time you open the query - once is enough.

HTH, RealHeavyDude.
 
Basically I think I did not get what it is you're trying to achieve.

I think you don't need to use a dynamic query object at all. As long as you don't change the buffers associated with a query and the order of the buffers in the join, you don't really need a dynamic query object. Instead you can grab the handle of an existing static query and use it as a static query object. Via the handle to that static query object you can do everything you need as long as you don't need to change the buffers - which I think is the case in your example.

You can use the QUERY-PREPARE method to change the where clause and sort order.


Heavy Regards, RealHeavyDude.
 
Back
Top