Reporting: Example of using API Methods in Dispatching Report to bring in Unit's Custom fields

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 Custom fields in the Sample dispatching report from the service workorder grid. Normally the unit’s custom fields are not available for reporting off of from the available datasets in the Service Workorder grid, but with the API we can do so.

  1. Download and import the sample report template [Sample Dispatching Report with API bringing in Unit’s Custom0 Custom1]( Dispatching Report with API bringing in Unit’s Custom0 Custom1 ) and review its scripts for an example of use.

  2. You will also want to refer of course to the business object library.

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

[i]using GZTW.AyaNova.BLL;

using CSLA;[/i]

  1. Example ofwhat 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 for better performance

//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 GetCurrentColunValue on it’s the woitem id
Guid gWOItemID=new Guid(DetailReportItem.GetCurrentColumnValue(“ID”).ToString());

//now that we have the Item, now 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());

//and this displays the unit’s custom0 field’s data now that the unit is identfied above
//Use the c# question mark conditional operator to display alternate text if the field is empty
label7.Text = string.IsNullOrEmpty(u.Custom0) ? “Custom 0 is empty” : u.Custom0;

//Use the c# question mark conditional operator to display alternate text if the field is empty
label8.Text = string.IsNullOrEmpty(u.Custom1) ? “Custom 1 is empty” : u.Custom1;




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: