Reporting: Example of using API Methods to bring in Unit's Warranty information

The following topic is about using the AyaNova developers API with reports are examples we have provided for experienced developers.

Also see other examples in the API and Development section of this forum - look for the posts that title is “Reporting: Example of using API Methods to…”

If you do not have development experience, we are happy to provide you with a quote to prepare a specific custom report that uses the API to obtain data not available through its datasets. Contact with details of what you would like - i.e. from what grid the report would be available from, what data it is that you want, example of use, etc.

In this example, we want to show in a detailed report template the unit’s warranty information that displays in the service workorder entry screen

  1. Download and import the sample report template [UNIT WARRANTY INFO Sample]( WARRANTY INFO Sample and review its scripts for an example of use. You will also want to refer of course to the business object library.

  2. As always, declare the namespace in the Before Print for the whole report in xtraReport1 " "

using GZTW.AyaNova.BLL;
using CSLA;

  1. Example of what is in the Before Print script for the detail band where the unit datafields are:

private void Detail2_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
///Only do this if there is a unit selected


//The Unit object does have a method to retrieve it’s ID from it’s serial number however the serial number column
//in the report contains other text besides the serial number so it’s not possible to use that method, instead we’ll get it from the workorder:

//first get the id of the Item - note the “DetailReportItem” I’m calling GetCurrentColumnValue on the woitem id
Guid gWOItemID=new Guid(DetailReportItem.GetCurrentColumnValue(“ID”).ToString());

//now that we have the Item we can fetch the workorder from the woitem id
Workorder w = Workorder.GetWorkorderByRelativeNoMRU(RootObjectTypes.WorkorderItem, gWOItemID);

//now get the correct workorder item from this workorder
WorkorderItem wi = w.WorkorderItems[gWOItemID];

//Now get the unit on this workorder item
Unit u = Unit.GetItemMRU(wi.UnitID,false);

//to display the unit's warranty info, need to 

            string sDate = "";
            if (u.WarrantyExpiryDateResolved != null)
                sDate = ((DateTime)u.WarrantyExpiryDateResolved).ToLongDateString();
            switch (u.WarrantyStatusResolved)
                case WarrantyStatus.None:
                    label3.Text = string.Format("{0}", "Unit is not warrantied." );
                case WarrantyStatus.Expired:
                    label3.Text = string.Format("{0}{1}", "Unit's warranty expired: ", sDate);
                case WarrantyStatus.Active:
                    label3.Text = string.Format("{0}{1}{2}{3}","Unit is warrantied until: ", sDate, " with terms: ", u.WarrantyTermsResolved);