Variants and passing to Report.RUN

kaybeekaybee Member Posts: 49
I have written a generic function which takes a variant as its parameter and a report ID. The idea is to be able to pass any type of record to the function such as Customer, Vendor, Item, Production Order etc... and then produce a report from it.
Function: 
DoSomething(ReportID : Integer; SomeRec : Variant Value) {
REPORT.RUNMODAL(ReportID, FALSE, FALSE, SomeRec)
}

But this does not work? Navision just crashes and restarts. What's the best alternative without having to do multiple case/if statements to cast it back to a specific record type?

Comments

  • SogSog Member Posts: 1,023
    So you call a report with a variant as the final parameter instead of a record.
    No wonder NAV crashes.
    Could you explain why this function would be usefull?
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • kaybeekaybee Member Posts: 49
    Hi, Rather justifying its usefulness, perhaps I should explain what I am trying to achieve instead.

    I am trying to write a generic function to print a particular report to a default printer but also passing the correct record to the report. Is this possible?

    I would be using this as a means of converting any Navision report to PDF and saving it to a directory.
  • Yashojit_PandhareYashojit_Pandhare Member Posts: 38
    try this


    rpt1.SETTABLEVIEW(rec1);
    rpt1.RUNMODAL;


    where in you declare
    rpt1 as a variable of type report and subtype= reportid/report name of the report you want to run
    and rec1 is the variable of type record
  • SogSog Member Posts: 1,023
    If you are on NAV 09 then I suggest to use the report.saveaspdf function instead of creating your own.
    On the other hand, the current report-handlers should give enough possibilities for modification.
    I created a print-to-pdf function with these tables.
    Report selection and printer selection tables are the ones you need.

    But for a generic function, I don't think with the objects NAV lets us use are sufficient.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • GRIZZLYGRIZZLY Member Posts: 127
    How about writing special function and sending TableNo and Primary Key values?
    Then, in report you can use RecordRef and FieldRef functions for the record, which table and primary key fields equals received parameters.
    For most tables in NAV not more then 3 fields in Primary Key is used.
    Sincerely yours, GRIZZLY
    Follow my blog at http://x-dynamics.blogspot.com
Sign In or Register to comment.