Microsoft Word can be used to render reports created with the Report Writer. You will create a Microsoft Word template that defines how the data for the report will be displayed in the Word document. Refer to the Report Writer documentation for details about how to create a Word template for a report. To use a Word template for a report, you must do the following:
To make a report template-enabled, you must register a function trigger for the IsTemplateEnabledReport() function of the syReportLookup form. Template-enabled reports can be selected in the Reports lookup.
The following example shows the registration for this trigger.
local boolean result; l_result = Trigger_RegisterFunction(function IsTemplateEnabledReport of form syReportLookup, TRIGGER_AFTER_ORIGINAL, function IG_IsTemplateEnabledReport); if l_result <> SY_NOERR then warning "Trigger registration for Word Template reports failed."; end if;
In the trigger processing function, you must check the product ID and resource ID of the report that are passed in. These values indicate the report that is being checked to find out whether it is template-enabled. If the product ID matches your product, and the report ID matches a report that you want to be template-enabled, return the value true from the function. The following example is the IG_IsTemplateEnabledReport() trigger processing function for the sample integrating application. It examines the product ID and resource ID passed into the function, and compares them to the resource IDs for the reports that are to be template-enabled. If the IDs match, the value true is returned from the function.
function returns boolean result; in 'Product ID' nProdID; in Resid nResID; if nProdID = IG_PROD_ID then {It's our report. Indicate that it is template enabled.} case nResID in [resourceid(report IG_Leads), resourceid(report IG_Leads_List)] result = true; end case; end if;
When a report is run, Microsoft Dynamics GP must be able to retrieve the Word template that is used for the report. If a Word template can be found for the report, then the user can choose to have the report rendered by Microsoft Word.
The Report Destination window that is automatically displayed by the run report or run report with name statements will automatically retrieve a Word template for a report if a template has been created. If a Word template is found, the “Template” choice will be added to the report type list. Otherwise, only the “Standard” report choice will be available.
If you have implemented a Report Options window for your integration that displays a Report Destination window, you must modify your code that opens the Report Destination window to allow it to find the a Word template for a report. The Report_Destination form and window in the Dynamics.dic dictionary are typically used for report options. The code in your Report Options window that opens the Report Destination form must set the product ID and resource ID fields in the Report_Destination window. The Report_Destination window uses these values to find out whether a Word template has been created and assigned for the report. If one has, the “Template” choice will be added to the Report Type list.
The following example is the change script for the Destination button in the Leads Report Options window in the sample integrating application. It opens the Report_Destination window from the Dynamics.dic dictionary, allowing the user to select the report destination. Notice that the values of the Product ID field and the Resid field in the Report_Destination window are set to the values for the current report. This allows the Report_Destination window to retrieve a Word template that has been set up for the report.
local string l_Filename; {Verify that an option name has been entered} if empty('(L) Report Options') then warning "Please select an option first."; focus '(L) Report Options'; else open form Report_Destination return to '(L) Dummy Return'; '(L) Button Flag' of window Report_Destination of form Report_Destination = true; 'Financial Report Name' of window Report_Destination of form Report_Destination = "Leads"; '(L) Report Option' of window Report_Destination of form Report_Destination = '(L) Report Options'; {Set product ID and resource ID so that a template can be used if one has been set up.} 'Product ID' of window Report_Destination of form Report_Destination = IG_PROD_ID; if 'Report ID' of window 'Leads Report Options' = ReptID_LeadsWithOptions then Resid of window Report_Destination of form Report_Destination = resourceid(report IG_Leads); end if; if 'Report ID' of window 'Leads Report Options' = ReptID_LeadsList then Resid of window Report_Destination of form Report_Destination = resourceid(report IG_Leads_List); end if; {Have not opened the destination window or retrieved a report option} if '(L) Dummy Flag Destination' = false then 'Print to Printer' of window Report_Destination of form Report_Destination = true; else 'Ask Each Time' of window Report_Destination of form Report_Destination = 'Ask Each Time' of table IG_Leads_ROPT; {Set the Export Type} if 'Export Type' of file IG_Leads_ROPT > 1000 then 'Export Type' of window Report_Destination of form Report_Destination = 'Export Type' of file IG_Leads_ROPT - 1000; else 'Export Type' of window Report_Destination of form Report_Destination = 'Export Type' of table IG_Leads_ROPT; end if; {Display the native path} l_Filename = Path_MakeNative('File Export Name' of table IG_Leads_ROPT); 'File Export Name' of window Report_Destination of form Report_Destination = l_Filename; 'If File Existing' of window Report_Destination of form Report_Destination = 'If File Existing' of table IG_Leads_ROPT; 'Print to File' of window Report_Destination of form Report_Destination = 'Print to File' of table IG_Leads_ROPT; 'Print to Printer' of window Report_Destination of form Report_Destination = 'Print to Printer' of table IG_Leads_ROPT; 'Print to Screen' of window Report_Destination of form Report_Destination = 'Print to Screen' of table IG_Leads_ROPT; end if; run script '(L) Dummy PRE Window' of window Report_Destination of form Report_Destination; end if;