Using the AyaNova API to generate an AyaNova report as a pdf file

The following is a snippet of code that shows how to generate an AyaNova report to disk as a .pdf file.
This is undocumented in the normal API docs but the information below should get you going, post any follow up questions here.

Keep in mind that the GetReportAsPDF method returns a memory stream object which is very versatile (you could also transmit it to a user over http for example) but for simplicity we’ll show writing it to disk.

There are two prerequisites to do this that go beyond the normal api usage.

  1. You will need the current release of AyaNova and the business object library patch number 4 (released today Feb 25 2016) or newer
    to check for this run AyaNova, select Help and About and scan down the list and you should see the following:

Business object assembly: GZTW.AyaNova.BLL.dll 7.3 (Patch 4)

You will need Patch number 4 to be able to access the report generator class and methods.

  1. Some reports will require a reference to the DevExpress.Data.v10.2 assembly found in the AyaNova program files folder where you normally make your references required for API use however you never need to call any code in that assembly yourself.

Here is a sample console application in C# illustrating writing a detailed workorder report for a random service workorder to disk with some additional code to help the savvy developer find the required report ID and clue to the business object required to drive that report through code.

//******* SAMPLE ********************
//The AyaNova business object library:
using GZTW.AyaNova.BLL;

//The security library required for
//processing the login
using CSLA.Security;

//Used for login confirmation
using System.Threading;
//*************************************

//system .io to write out the report file stream
using System.IO;

namespace reportTest
{
class Program
{
static void Main(string[] args)
{
//============================================
//GENERAL API STUFF
//initialize the business object .dll
try
{
GZTW.AyaNova.BLL.AyaBizUtils.Initialize();
}
catch (Exception ex)
{
//“crack” the exception to get to the innermost exception
while (ex.InnerException != null)
ex = ex.InnerException;

            throw (ex);
        }

        //authenticate
        AyaBizUtils.Login("manager", "letmein");
        //===============================================

        //Now we have api access


        //-----------------------------------------
        //HERE IS SOME CODE TO ITERATE ALL REPORTS IN AYANOVA TO GET MORE INFO
        //THIS IS NOT REQUIRED TO GENERATE A REPORT, IT'S FOR INFORMATION PURPOSES
        ReportList rl = ReportList.GetList("");
        foreach (ReportList.ReportListInfo i in rl)
        {
            //for example, only view Detailed service workorder based reports:
            if (i.LT_Report_Label_ReportKey != "WorkorderServiceDetailed") continue;

            //NOTE: the report key is often a clue to indicate which business object in the AyaNova
            //API is required to supply data to that particular report

            //put a breakpoint here to get the report id and list info you need 
            string s = i.ToString();

            //for example the sample report "Sample Detailed Service Workorder with Grand Total Report"
            //is guid 588d01bc-d191-4b9c-a6b1-2e820150523c
        }
        //----------------------------------------------


        //-----------------------------------------------
        //OUTPUT A DETAILED SERVICE WORKORDER REPORT TO A PDF FILE:            

        //get 10 random service workorders without any criteria           
        WorkorderServiceList wsl = WorkorderServiceList.GetList("", 10);

        //get the id of the first service wo in the list
        Guid WorkorderIDToReport = wsl[0].LT_O_Workorder.Value;

        //Get the data for the workorder
        object o = WorkorderServiceDetailedReportData.GetItem(WorkorderIDToReport);

        //Get the report
        Report r = Report.GetItem(new Guid("588d01bc-d191-4b9c-a6b1-2e820150523c"));

        //generate the pdf report to a memorystream
       //NOTE: parameters for GetReportAsPDF are: first is the report object and second is any of a variety of AyaNova business objects (generally lists that are displayed in the UI) see the reports 
       //the reports "key" property generally points to which business object that report will require.
        MemoryStream ms = GZTW.AyaNova.BLL.ReportGenerator.GetReportAsPDF(r, o);

        //write the report in the stream out to a file
        using (var fileStream = File.Create("C:\	emp\\file.pdf"))
        {
            ms.Seek(0, SeekOrigin.Begin);
            ms.CopyTo(fileStream);
        }
        //-----------------------------------------------

    }
}

}