Prevent closing report until it is finished.

falcofalco Member Posts: 3
Hello.

This is my first post in this forum, so please be patient ;)

My code consists of a report, that modally runs a form (in OnAfterGetRecord for one of data items).

The problem is that while this modal form is not closed nothing stops user from closing the report. When the report is closed, modal form is left alone, and after closing it, Navision crashes (Navision version 4sp2).

I tried setting form as global variable and doing clear for it, in trigger OnPostReport, that did not work. Then I created a procedure in form, that closes it, and put the code that calls it again in trigger OnPostReport. That did not work either, because it seems that OnPostReport is not run, if report is closed in the middle of processing.

I guess a solution would be something like the subject of this topic, but I am afraid it is not possible.
Does anyone have other ideas?

In case someone asks what is the use of running a form in the report, here is my answer - when Request form is run, we yet do not know what filters will be put on the report, we know them only when report is actually run. My form needs to know these filters that's why I can't use request form so I don't see other way.

Thank you,
Falco

Comments

  • kinekine Member Posts: 12,562
    1) It is not good to open forms from report
    2) Why you are doing that? Think about another way how to do that. Reports are there for reporting and batch processing. In this you never needs running another form...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ara3nara3n Member Posts: 9,255
    Also, how are you running the form, can you provide the code?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • SobyOneSobyOne Member Posts: 20
    Try these:

    1. Change the report to "Processing Only"

    OR

    1. Create a new report that is "Processing Only"
    2. Print the results with a second report by turning off the "User Request Form"
    _\~ () ]3 `/ () |\| [-
    http://www.SobyLand.com
    651-815-0698
  • falcofalco Member Posts: 3
    Thank you for replies!
    kine wrote:
    1) It is not good to open forms from report
    2) Why you are doing that? Think about another way how to do that. Reports are there for reporting and batch processing. In this you never needs running another form...

    Although I already explained why I am opening form and not using request form (see the last paragraph of my first post), I can go a little more in detail about it. The report is sales invoice. Here in Latvia we need to display item carrier information on invoices (carrier company details, driver name, car registration No.).
    There can be various cases with item carriers:
    1) Customer might use it's employees to carrry information
    2) Customer might use services of carrier company
    3) Seller might use it's employees for item carrying

    Of course it is not very convenient to always enter this information manually therefore I added functionality of registering item carriers and linking them to customers, vendors (for purch. credit memo), and company information (for companies employees).
    Now, when invoice is printed, modal form is displayed and user can either select carrier from already input list, or manually enter this information.

    As I stated before - request form can not be used for this because when request form is run, we can't yet access the filters that has been put on the report therefore we can't tell the customer No.
    Another solution would be to set the invoice number as parameter for the report, but that is quite ugly - need to change 5 forms and code will not work as standard report selection.

    If I don't find answers here I will probably change the design so that item carriers are input in invoice forms. That also means changing 5 forms and 2 codenunits (for posting sales and purch. credit memo), but atleast report will be independent from form and standard report selection code will be used. It was not initially done so because solution grew from one of manually entering information in Request Form.

    I am not very eager to change the code though because current solution actually works quite good. The only problem is with closing of report while modal form is still open.
    To be honest - I think that is a bug of Navision, because opening forms from reports is not forbidden (compiler allows it). Navision should have either not allowed closing of report while it has modally open form, either closed all open forms when closing the report, or at least run the trigget OnPostReport, so that I can close the form myself. Nothing of this happens and Navision just crashes.
    Of course after this I can just agree that it probably is not good to open forms from reports.

    Here is my code of opening the form in trigger Sales Header - OnAfterGetRecord():
      CLEAR(CarrierInformation);
      CarrierInformation.LOOKUPMODE := TRUE;
      CarrierInformation.SetReceiver("Sell-to Customer No.",TRUE);
      IF CarrierInformation.RUNMODAL = ACTION::LookupOK THEN BEGIN
        CarrierInformation.GETRECORD(ItemDeliveryDriver);
        //Company name and VAT No. are saved into temporary fields.
        CarrierName := ItemDeliveryDriver."Temp Field 1";
        CarrierVATNo := ItemDeliveryDriver."Temp Field 2";
        CarNo := ItemDeliveryDriver."Car Registration No.";
        DriverName := ItemDeliveryDriver."Name and Surname";
      END;
    

    Falco.
Sign In or Register to comment.