Reporting: Example of using API Methods to get a list of all units owned by that client

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 support@ayanova.com 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.

This API example shows getting a list of all units tied to each client but from the Clients grid. Something you can not do without using the developers API as units are not part of the client report grids.

  1. Download and import the sample report template[API report template from Clients grid displaying Units owned by client.zip](http://www.ayanova.com/Downloads/Reporttemplates/API report template from Clients grid displaying Units owned by client.zip ) and review its scripts for an example of use. As an experienced developer, you will also want to refer of course to the http://api.ayanova.com business object library.

  1. You need to declare the namespace in the Before Print for the whole report in xtraReport1 properties. This will save time by not having to type the entire namespace in front of all AyaNova business object names: " "

[i]using GZTW.AyaNova.BLL;

using CSLA;[/i]

  1. A Before Print script is created for the Detail band that will have the labels that will be displaying the data we get.

" "

[i]private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)

{[/i]

[i]//For testing purposes show the Client ID value

label2.Text=Client.IDFromName(GetCurrentColumnValue(“LT_O_Client”).ToString()).ToString();[/i]

[i]//Get the client’s internal ID value from their name

Guid gClientID=Client.IDFromName(GetCurrentColumnValue(“LT_O_Client”).ToString());[/i]

[i]//Prepare a stringbuilder to contain the list of units

System.Text.StringBuilder sbUnits = new System.Text.StringBuilder();[/i]

[i]//Get a list of units this client owns

UnitPickList upl = UnitPickList.GetListByClient(gClientID);

if (upl.Count > 0)

{

foreach (UnitPickList.UnitPickListInfo i in upl)

{

sbUnits.Append(i.UnitName());

sbUnits.Append("\r");

}

}

else

sbUnits.Append(“No units owned by this client”);[/i]

[i]label8.Text=sbUnits.ToString();

}[/i]

  1. We use the API IDFromName method to display the clients internal ID in label2

  2. To display the units owned by the client, we first get the Client’s internal id, then prepare a stringbuilder to hold the list of units (as some clients have more then one), and then use the UnitPickList method GetListByClient to get the list of units using the business object property.

Example printout showing clients listed followed by all of its units