Edit

DoReport (reportName, format, title, parameters...)

Result Type:  a path string

Definition:  Generates a report, either returning the text of the report, or a path to the generated output file.

Format can be "pdf", "html", "text", "preview" or "". For the first 3, the return value is the path to a temporary file that will be deleted when you quit. For a an empty or unknown format string, the function will return the actual tab-delimited report output instead of a path.

Parameters should be strings in the form "paramName=paramValue". Parameters are inserted into the name table and are available to the report. An associative array is also acceptable—each element of the array will be inserted into the name table with its key as the variable name. Use an associative array if you have a parameter that is a selection.

To specify the period range for a financial report you must supply parameters named from and to which may be dates (as yyyymmdd) or period numbers (dates will be mapped to periods). The report will run for each period in the range. If no period range is specified, the current date will be assumed.

Examples: 

doreport("Balance Sheet", "preview", "Balance Sheet", "from=20160331", "to=20160331", "include_unposted=1") // to preview
let t = doreport("Balance Sheet", "", "Balance Sheet", "from=20160331", "to=20160331") // to tab-delim text string
let h = doreport("Balance Sheet", "html", "Balance Sheet", "from=20160331", "to=20160331") // to html file

By default, any custom control variables will take on the values last saved in the report document. You can pass values for custom controls defined in the report, but to have your passed values override those last stored in the report document, you must include an additional parameter "override_doc_custom=1".

As a network client. you can force the report to run on the server (even when latency is low) by passing "prefer_remote=1".

Example:  In this case, the_name_code is the name of a custom control, so we must pass "override_doc_custom=1" as well in order to override the value stored in the report.

let pdfPath = DoReport("Statement.crep", "pdf", "Statement", "the_name_code=" + n.code, "override_doc_custom=1")

Availability:  MWScript handlers. This function is closely analogous to the command line and REST doreport commands. A similar DoReport command is also available to Applescript/COM.

Printing Formatted Text: 

As of version 9.1.7, there is a special built-in report "~textreport" that allows you to present text in a semi-formatted fashion, obviating the need to make your own custom report. Your text is passed as a parameter to the report, which will output it in a mono-spaced font. To use, pass your text in the "Contents" parameter:

doReport("~TextReport", "preview", "Report Display Name", createArray("Contents", myText))

A few points to note:

  • Lines in the report are ended with "\n"
  • Lines in the report should be no longer than 80 characters. Lines longer than this will be truncated.
  • Tab characters ("\t") can be used in the text provided you have a Cols directive (see below)
  • A line with a single hyphen/dash, will output a line across the page

Lines starting with a # are treated as directives to the report

  • #Page: Force a page break
  • #Cols=w1,w2, ... : will set columns of the specified width in the report for lines with tab characters. These will be left justified unless an "R" is appended to the width. For example #cols=10,10R will give two columns, the second being right justified. The output will be undefined if the number of tabs on a line is greater than the number of columns.
  • #Other text: Any other line starting with a # will output in bold.

Example:

    let myText = "#cols=35,33R\n#Production Report\t"+datetotext(time(), DateFormShortDateAndTime)+"\n#Shift: One\n"
    let myText = myText + "\n-\nThis is what we did today\n"
    let myText = myText +"\n#cols=10,40,8R,8R\n#\tItem\tOrder\tMake\n\n"
    let myText = myText + "\tBA100\t25\t15\n"
    let myText = myText + "\tBB100\t40\t40\n"
    let myText = myText + "\tBC100\t5\t0\n"
    let mytext = mytext + "-\n#Page"
    doReport("~TextReport", "preview", "Production Report", createArray("Contents", myText))

Will result in the following: