Options

Choosing Reports from a Form

AlxAlx Member Posts: 38
Good month to everybody!

This is my problem: I have 2 different reports for a Sales Order and I would like to give the user the ability to choose which one of these should be printed for a specific Order, at runtime.
If I understood correctly, in the Report Selections I can specify which reports are to be run, but they are run sequentially, one after the other.
What I want is to be able to choose from a list.
Is this possible?

Thanx in advance,

Alx

Comments

  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Alx,

    This should be easy when you modify cu. 229.

    In function PrintSalesHeader you can add
    Old Code
    
    ReportSelection.SETFILTER("Report ID",'<>0');
    ReportSelection.FIND('-');
    REPEAT
      REPORT.RUNMODAL(ReportSelection."Report ID",TRUE,FALSE,SalesHeader)
    UNTIL ReportSelection.NEXT = 0;
    
    New Code
    
    
    ReportSelection.SETFILTER("Report ID",'<>0');
    IF SalesHeader."Document Type" = SalesHeader."Document Type"::Order then 
      if form.runmodal(0, ReportSelection) =  Action::lookupok then
        reportselection.setrecfilter;
    
    ReportSelection.FIND('-');
    REPEAT
      REPORT.RUNMODAL(ReportSelection."Report ID",TRUE,FALSE,SalesHeader)
    UNTIL ReportSelection.NEXT = 0;
    
    

    I have not tested it, maybe the setrecfilter does not workbut it is worth a try.
  • Options
    AlxAlx Member Posts: 38
    Hi Mark,

    Thanx for the tip, but I tried it and, indeed, the SETRECFILTER does not work! Any other suggestons?

    Alx
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Hi,

    I've tested it and after a small modification it worked

    New Code
    IF SalesHeader."Document Type" = SalesHeader."Document Type"::Order THEN 
      IF FORM.RUNMODAL(FORM::"Report Selection - Sales", ReportSelection) =  ACTION::LookupOK THEN
        ReportSelection.SETRECFILTER; 
    

    I got the error
    Form 0 does not exist...
    

    Please post your code if it still does not work
  • Options
    AlxAlx Member Posts: 38
    It works !!!!!

    Bedankt!
  • Options
    AlxAlx Member Posts: 38
    But today it stopped working... :roll:

    When I try to print I get the Report Selection - Sales form with S.Quote as Usage and I can't select any other Usage.

    Here is the code:

    ReportSelection.SETFILTER("Report ID",'<>0');
    ReportSelection.SETFILTER(Usage,'S.Blanket');
    IF SalesHeader."Document Type" = SalesHeader."Document Type"::"Blanket Order" THEN
    IF FORM.RUNMODAL("Report Selection - Sales", ReportSelection = ACTION::LookupOK THEN
    ReportSelection.SETRECFILTER;
    ReportSelection.FIND('-');
    REPEAT
    REPORT.RUNMODAL(ReportSelection."Report ID",TRUE,FALSE,SalesHeader)
    UNTIL ReportSelection.NEXT = 0;

    I ran this through the Debugger and from what I understand, ReportSelection only stores the record selected on the form, in other words it behaves like an OUT parameter. The filter I have set on ReportSelection before calling the form is NOT passed on to the form.

    I tried to experiment with RUNMODAL(Form) and Form.SETTABLEVIEW but the documentation is not really helpful...

    Any hints?

    Alx
  • Options
    AlxAlx Member Posts: 38
    Correction:


    IF FORM.RUNMODAL(FORM::"Report Selection - Sales", ReportSelection) = ACTION::LookupOK THEN

    instead of


    IF FORM.RUNMODAL("Report Selection - Sales", ReportSelection = ACTION::LookupOK THEN
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Put the Setfilter after the condition ??
    ReportSelection.SETFILTER("Report ID",'<>0'); 
    IF SalesHeader."Document Type" = SalesHeader."Document Type"::"Blanket Order" THEN BEGIN
      ReportSelection.SETFILTER(Usage,'S.Blanket'); 
      IF FORM.RUNMODAL("Report Selection - Sales", ReportSelection = ACTION::LookupOK THEN 
      ReportSelection.SETRECFILTER; 
    END;
    ReportSelection.FIND('-'); 
    REPEAT 
    REPORT.RUNMODAL(ReportSelection."Report ID",TRUE,FALSE,SalesHeader) 
    UNTIL ReportSelection.NEXT = 0; 
    
    
  • Options
    AlxAlx Member Posts: 38
    Nope, it doesn't make any difference. :|
    What I need is a way to pass a filter TO the form, as it seems that ReportSelection only returns a record FROM the form.
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Hi,

    Looks like something got completely messed up.

    Could you e-mail me the codeunit so I can have a look at the complete code?

    You can also send a p.m.

    I am affraid I cannot help only having fragmented bits of code.
  • Options
    Michael_SchumacherMichael_Schumacher Member Posts: 81
    Hi There,

    Any Results for this Problem?

    I'm have the same task, a customer need's different Invoices for his Customers throughout the world. In Chile for Example are other informations about customs needed as e.g. in China or even in Germany.... so it results in 20 different reports for invoice :shock:

    how to choose....
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Hi Michael.

    The problem is solved.

    For you I think it is best to add an field 'INVOICE CODE' to the customer card and the report selections.

    This way, every customer can have his own report if nessesairy.

    If you copy this to the sales document and sales Invoice you can filter on this field in codeunit 229. :D

    (This should be standard Nav!) :!:
  • Options
    Michael_SchumacherMichael_Schumacher Member Posts: 81
    Hi Mark,

    Yeah in the meantime I found the Problem from alx ;-)

    pressing Ctrl-Shift-F7 releases the filter and you can change the selection in the header ....

    But I think you're right with the invoices. As I remember, this form cannot be runmodal inside a transaction..... right :?:

    I thought about this extra field earlier. But my boss wanted a possibility to choose. Now I have arguments to take him away from this idea :mrgreen:
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yeah in the meantime I found the Problem from alx ;-)


    pressing Ctrl-Shift-F7 releases the filter and you can change the selection in the header ....

    The problem was in the form, there was a setfilter in the onopenform. We've created a new form.
    But I think you're right with the invoices. As I remember, this form cannot be runmodal inside a transaction..... right :?:

    Right. But there is no transaction, so the form can be run modaly without problems.

    I thought about this extra field earlier. But my boss wanted a possibility to choose. Now I have arguments to take him away from this idea :mrgreen:

    You can have a form, just don't use the standard navision report selection form.

    Hope this helps. :)

    PS. I've solved the problem with alx via email. You can have a copy if you want.
  • Options
    Michael_SchumacherMichael_Schumacher Member Posts: 81
    Yeah in the meantime I found the Problem from alx ;-)
    pressing Ctrl-Shift-F7 releases the filter and you can change the selection in the header ....
    The problem was in the form, there was a setfilter in the onopenform. We've created a new form.
    Yeah I know, that should be my next task.....
    But I think you're right with the invoices. As I remember, this form cannot be runmodal inside a transaction..... right :?:
    Right. But there is no transaction, so the form can be run modaly without problems.
    ok, that is good to know, maybe I mixed up some informations
    I thought about this extra field earlier. But my boss wanted a possibility to choose. Now I have arguments to take him away from this idea :mrgreen:
    You can have a form, just don't use the standard navision report selection form.
    Hope this helps. :)
    PS. I've solved the problem with alx via email. You can have a copy if you want.

    YESSSSSIR! This would help! E-Mail is on the way so you can answer to it ;-)
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Ok.

    Maybe I will mail it to Luc to, for the download section.
  • Options
    Michael_SchumacherMichael_Schumacher Member Posts: 81
    Unfortunately the report print of invoices is inside a transaction so no selection can be done :-(

    I put this
    IF ReportSelection.COUNT > 1 THEN
            IF FORM.RUNMODAL(FORM::"Report Selection", ReportSelection) = ACTION::LookupOK THEN
          // If user cancels all reports are printed !!!
              ReportSelection.SETRECFILTER;
    
    in the printreport() function but it's still inside transaction.

    Has anybody an idea where and how this selection can be made before transaction starts? I'm not sure where this begins
    What I know is that I have to store the filter in a variable until it is needed.
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What transaction is made then?

    Is it german functionality or is it customisation. It works fine in W1 and NL database?

    Do you get the classic form.runmodal message?
  • Options
    Michael_SchumacherMichael_Schumacher Member Posts: 81
    What transaction is made then?
    Invoice post & print
    Is it german functionality or is it customisation?
    standard german installation with this little lines for choosing report added
    Do you get the classic form.runmodal message?
    This was the first one I ever saw, it's the epos of what you can't do inside a transaction with the first thing is the runmodal... ;-)
    so I think it's the standard.

    in procedure run() first salespost(record) and then the print routines are invoked and then the commit :-(

    I do not want to place this commit before printing, because if there goes anything wrong you can't print again because there is no more invoice.
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Hi,

    If I understand right you have put a form.runmodal in the function Printreport of Codeunit 82.

    Before this funtion is called navision uses a trick to get the right shipment/invoice via the last posting no.

    Before this is done a COMMIT is raised in Codeunit 80.

    Unfortunately the trick done by navision causes the database/table to be locked again.

    There can be a few solutions for this.

    One solution is to place a COMMIT in function PrintReport, this sould not be a problem because it was already raised in Codeunit 80.

    An other problem is to replace the SalesShptHeader and SalesInvHeader by temporary varaibles. This does the same trick to get the right filter but does not lock the table. I think Navision should have done this to :D

    Succes.
  • Options
    Michael_SchumacherMichael_Schumacher Member Posts: 81
    If I understand right you have put a form.runmodal in the function Printreport of Codeunit 82.
    YES! the lines posted 4 posts earlier ;-)
    Before this funtion is called navision uses a trick to get the right shipment/invoice via the last posting no.
    Before this is done a COMMIT is raised in Codeunit 80.
    Ooops I didn't see that. Otherwise I wouldn't have asked ;-)
    Unfortunately the trick done by navision causes the database/table to be locked again.
    There can be a few solutions for this.

    One solution is to place a COMMIT in function PrintReport, this sould not be a problem because it was already raised in Codeunit 80.

    An other problem is to replace the SalesShptHeader and SalesInvHeader by temporary varaibles. This does the same trick to get the right filter but does not lock the table. I think Navision should have done this to :D

    Succes.

    Yeah, I thought it commits after printing, so that if print goes wrong, the complete transaction will be rolled back.

    And it seems to be just this way, because when this form.runmodal message comes, the invoice is still there..... if I didn't turn numbers in my head......

    I have to try a little and think it over...

    Thanks for the hints.
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • Options
    elias_kelias_k Member Posts: 11
    Hello Alx,
    Table Report Selections has one more field from Greek Localization.
    You have to insert to No. Series with a sequence number, and the same No. Series with the next sequence number. So when you print this kind of report you are going to have two print-outs.

    (propably this change was made for the reason you want it!)

    Regards Elias
    give me some time
  • Options
    Joe_LittleJoe_Little Member Posts: 45
    Great Mod! Very clever.

    Here's one tweek that you could make to make it a little more graceful when users escape. The standard look and feel would be that no reports print instead of all printing. If you changed things slightly, it would be this way.

    Current Version:

    IF ReportSelection.COUNT > 1 THEN
    IF FORM.RUNMODAL(FORM::"Report Selection", ReportSelection) = ACTION::LookupOK THEN
    // If user cancels all reports are printed !!!
    ReportSelection.SETRECFILTER;

    //* End Change <<<

    ReportSelection.FIND('-');
    REPEAT

    Tweeked Version:

    IF ReportSelection.COUNT > 1 THEN
    IF FORM.RUNMODAL(FORM::"Report Selection", ReportSelection) = ACTION::LookupOK THEN
    ReportSelection.SETRECFILTER
    ELSE // Tweek
    ReportSelection.Setfilter("Report ID",0); // Tweek

    //* End Change <<<

    IF ReportSelection.FIND('-') then // Tweek
    REPEAT
Sign In or Register to comment.