Options

Previewing a report programatically

Cem_KaraerCem_Karaer Member Posts: 281
Hi everyone,

Is not there a way to preview a report in the C/AL code. I designed a report that does not require any options or any filters or any sorting schema. I can print it directly without letting it show its request form but I cannot preview it. Just showing up a form with only buttons is a wierd, non-Navision-looking situation.

If there is no way to prevent this technically, what can I do as respects aesthetics.
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 2005

Answers

  • jjanauskasjjanauskas Member Posts: 49
    As far as I know, there is no way to do that, except running it using request form :(
  • ara3nara3n Member Posts: 9,258
    You can use key stroke macro. Search mibuso on how to.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • MTCMTC Member Posts: 159
    To do it simply, place this in Report - OnOpenForm() which you can access through the request form designer. Remember to change {v} for whatever it is in the language you are using. You can even get the language code off Navision and then do a CASE on the different languages you are dealing with. % in SENDKEYS means ALT {v} means lowercase 'v' which is the shortcut for preview in the English version. The button says 'Preview'. In the Peninsular Spanish version it's {p} because the button text is 'Vista preliminar'

    WshShell is an Automation variable with subtype 'Windows Script Host Object Model' and object of WshShell. Thus, subtype is 'Windows Script Host Object Model'.WshShell
    CREATE(WshShell);
    WshShell.SendKeys('%{v}');
    CLEAR(WshShell);
    

    So, for Spanish and English, you can do this:
    CREATE(WshShell);
        IF CurrReport.LANGUAGE = 1034 THEN
            WshShell.SendKeys('%{p}') // Spanish
        ELSE
            WshShell.SendKeys('%{v}'); // English
    CLEAR(WshShell);
    

    If you want to control the behavior of this, you can create a function that you can call before you run the report, so that if run default it shows the request form, otherwise it will hide it if you call the function. In this case, you have a global variable, say HideForm - Boolean, and you have a global function as so that does HideForm := TRUE;

    The code in the Report - OnOpenForm() would then be:
    IF HideForm THEN BEGIN
        CREATE(WshShell);
            IF CurrReport.LANGUAGE = 1034 THEN
                WshShell.SendKeys('%{p}') // Spanish
            ELSE
                WshShell.SendKeys('%{v}'); // English
        CLEAR(WshShell);
    END;
    

    Good luck.
  • Cem_KaraerCem_Karaer Member Posts: 281
    Thank you MTC! It works.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
  • Cem_KaraerCem_Karaer Member Posts: 281
    And it is the smartest trick I have ever got about Navision :P (understandable if it is counted that I'm only one-yeared developer :D )
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
Sign In or Register to comment.