Reporting: Example of using API Methods to bring in Unit's Address fields into Service WO report

The following topics 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 the unit’s address fields in the Sample dispatching report from the service workorder grid. Normally the unit’s address fields are not available for reporting from the available datasets in the Service Workorder grid; with the API we can easily show the address fields.

  1. Download and import the sample report template [API Sample Dispatching Report bringing in Unit’'s address[] Sample Dispatching Report bringing in Unit’'s address 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

private void OnBeforePrint(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.GetItem(wi.UnitID);

//example to show the GUID of the unit in the label

// to show the actual serial number would use:

//or if I wanted to do set text and then show serial and purchased date all in one label:
label4.Text=string.Format("{0}{1}{2}", "unit with purchased date: ", u.Serial , u.PurchasedDate);

//or if I want to get the unit by the global settings unit name format
label5.Text = UnitPickList.GetListOfOneSpecificUnit(u.ID)[0].UnitName();

//whereas this displays the text plus the unit’s receipt number and custom2 field data(now that the unit is identified above)
label6.Text=string.Format(“unit’s receipt #: {0} with extension: {1}”, u.Receipt, u.Custom2.ToString());

//displaying unit’s address internal ID
label7.Text = u.GoToAddress.ToString();

//displaying unit’s actual address

label8.Text = u.GoToAddress.City.ToString();

label9.Text = string.Format(" {0}, {1} {2} {3} {4}", u.GoToAddress.DeliveryAddress.ToString(), u.GoToAddress.City.ToString(), u.GoToAddress.Postal.ToString(), u.GoToAddress.StateProv.ToString(), u.GoToAddress.Country.ToString());




The line below actually doesn’t display the internal GUID of the unit record

//example to show the GUID of the unit in the label

Instead, if you need to get the actual GUID of the unit record, you would use: