How do I differentiate between page exits?

bknoppbknopp Member Posts: 37
edited 2014-03-03 in NAV Three Tier
Hi all,

I'm new to NAV programming, and I have a bit of a stumper (at least for me). I have a page that prompts the user for five data values (all CODE types) that it passes on to a sub-form. All five must be populated in order to proceed to the sub-form.

My initial thought was to put the "are all the fields populated?" logic in the page's OnQueryClosePage trigger, but I need to be able to distinguish between:
  • User clicked "OK"
  • User clicked the "Close" button with the red "X" in the top right corner
  • User pressed the ESC key

Obviously I only want to display the sub-form if the user clicks "OK".

I walked through the code in the debugger to watch the event, and the "CloseAction" parameter was "OK" for both the "OK" and "red X Close" buttons, so that won't work. My Bing-fu failed to find any guidance on the web, and none of the forum posts I've seen here address my question.

All suggestions are welcome, 'cause I feel like ](*,)


  • Options
    Rob_HansenRob_Hansen Member Posts: 296
    There are a few different ways to approach this. I'll give you a couple here.

    If you really need a header/subform structure (where the user fills in fields on the header first and then the subform can be used based on those values), either use a temporary table for the subform or set an initial filter that shows no results. Once the user fills in the header fields, have a page action for them to run ("Generate" or "Proceed" or whatever you want to call it) that generates the records for the subform (if temporary) or lifts the filter (so the records are shown).

    If you don't need a header/subform structure, I've adopted an approach of using a processing only report to prompt for the values. So, I create a report with a request page that has the fields I want to prompt for. I set up a single Integer data item where Number=CONST(1) (or MaxIteration = 1), add a global variable (eg. gblnClickedOK) to the report, and then code OnAfterGetRecord for the integer data item to set gblnClickedOK := True. If the user closes or cancels the report, the variable won't be set...so you know that they clicked OK if it is set. Then, I call the report in a loop until the results are okay. i.e.:
    lblnResultOK := FALSE;
      lrptGetSettings.GetResults(lblnClickedOK,lintOtherValue,ltxtOtherValue,etc.);  //Function in report to return results
      IF NOT lblnClickedOK THEN EXIT;  //Or ERROR('');
      IF <Logic to check if entered values are okay> then
        lblnResultOK := TRUE;
    <Code here to open a new page using the entered values>

    If you use the SaveValues property of the request form on the report, it will hold the user's values so they don't have to re-enter them on each error. I sometimes explicitly pass the values to the report when i need more control over the initial settings.
  • Options
    jversusjjversusj Member Posts: 489
    I am running into this same issue in NAV2013, and I cannot use a report or header/subform approach to solve it.

    From a Sales Order, users can select one or more Sales Lines and then click a subpage action to launch a Freight Estimate function (code lies within a codeunit). This code will create a theoretical packout (Parcel and LTL) and create temporary records in some custom tables, ultimately calling a named page variable with a RUN call. I have to use a named page variable because I need to call a function in the page from the codeunit prior to RUN. I cannot seem to use a named page variable with an IF pagevariable.RUN = ACTION::OK (or LookupOK) call (will not compile) within the codeunit.

    The page launches and displays the theoretical packout. The user can then make some parameter entries and click a page action to call a webservice to rate the shipment. The user can then select from the returned rates regarding the service they want to us. If they click OK to close the page, I want to push the selected Shipping Agent and Service back to the "packed" sales lines that called the page. This works just fine, but as the original post states, the code gets executed even if they click ESC or Red X the page to close. It's always OK.

    I've seen other examples in our code where LookupOK has been used, but since I cannot seem to use a named page variable with that approach, I don't know what else to do. Any suggestions?
    kind of fell into this...
Sign In or Register to comment.