Riyaz wrote:Hi There
Trying to call the print of a particular work order report on a custom button click under utility. Unable to find the print function of the work order, below is an example what I found for SalesOrder , can you pls guide me towards an equivalent for WorkOrder
public static void PrintInvoice(SalesOrder salesOrder, string formatName)
{
foreach (SalesOrderReport salesOrderReport in salesOrder.GetCandidateReportsToPrint())
{
if (salesOrderReport.Name == formatName && salesOrderReport.BillingType == salesOrder.BillType)
{
salesOrder.Print(new JiwaCollection<SalesOrderReport>() { salesOrderReport });
return;
}
}
}
Sales orders is totally different, as there are different report types (invoice, delivery docket, et cetera) so isn't the best comparison.
Every Maintenance.UserInterface type form (which the work order form is) has a PrintRecord method - just invoke that, passing as a parameter the ReportDefinition to print.
The form also has a ReportDefinitionCollection property which is the list of defined reports for that form - so one of those items is what you want to pass as the ReportDefinition to the PrintRecord method.
For example, the following will print the first report defined in the report definition collection:
- Code: Select all
workOrderForm.PrintRecord(workOrderForm.ReportDefinitionCollection(1))
Obviously you will want to locate which report using some other way, so a bit of Linq will do the job there:
- Code: Select all
// Print report with description "test"
JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.FormReports.ReportDefinition reportDefinition = workOrderForm.ReportDefinitionCollection.Cast<JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.FormReports.ReportDefinition>().Where(x => x.Description == "test").FirstOrDefault();
Example plugin attached adds a ribbon to the Work Order form "Custom Print" and when pressed prints a report where the Description is "test". The print method also has commented out other criteria for which report to print.