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.

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);




am using this for our own reporting. How would I pull in the model information for the unit ?

I think I would have to use the unit ID to find the UnitModelID.

Once I have that what I want to do is get the custome field information (Custom0, Custom1 etc).

Know the theory, so far have not been able tio implement it !!!


Hello Martin, once you have the Unit object (as per the example here) that contains the Unit model Id which is all you need to then fetch the Unitmodel object in a similar fashion to how the unit is retrieved.
The api is documented here:

Specifically this page shows you the Unit’s fields and among them the UnitModelId field:

And this page contains the info about UnitModel:

Which, as you can see from that page, contains the standard GetItem method which can be used to retrieve it.

Thanks the help John.

Just in case anyone else reading this:

UnitModel m=UnitModel.GetItem(u.UnitModelID);

label6.Text = m.Name.ToString(); // Display the model name