Reporting: Example of using API Methods to display additional Rate data in a 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 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.

Normally via a detailed service workorder report, the Rate Cost, Charge, Account Number and Description etc are not available in the Field List.

Using the API, you can obtain and display this information in a report.

  1. First example refer to the sample report template http://www.ayanova.com/Downloads/ReportTemplates/APISampleDispatchingReportwithadditionalRatefields.zip and review its scripts for an example of use.

  2. You will also want to refer of course to the http://api.ayanova.com business object library.

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

[i]using GZTW.AyaNova.BLL;

using CSLA;[/i]

  1. And then below is a copy of what is in the details Before Print script " "

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

{[/i]

object o = DetailReportScheduledUsers.GetCurrentColumnValue(“ID”);

[i]if (o != null)

{

System.Guid g=(System.Guid)o;

//See if it’s empty:

if(g!=Guid.Empty)

{

//now we get the scheduled user object using the id that we got above

//GetDescendant<T> where T is the type of the descendant object

WorkorderItemScheduledUser wis = Workorder.GetDescendant<WorkorderItemScheduledUser>(g);

//below shows displaying properties of that specific scheduled user object - in this case, its Start Date

label4.Text = wis.StartDate.ToString();[/i]

[i]//now we want to get the ID of the rate of that scheduled user

//but rate could be empty so only do this if there is actually a rate selected

if (wis.ServiceRateID!=Guid.Empty)

{

//Fetching a list of one rate means we can access the first item in the list

//using array notation:

RatePickList.RatePickListInfo i=RatePickList.GetListOfOneSpecificRate(wis.ServiceRateID)[0];

//now can access all the properties of this single RatePickListInfo item:

//string RateName=i.Name;

//decimal RateCharge=i.Charge;

//etc etc[/i]

[i]label1.Text = i.Name;

label2.Text = i.Charge.ToString();

label5.Text = String.Format(“the charge is: {0} for rate: {1}”, i.Charge.ToString(“C”), i.Name);

label7.Text = i.Charge.ToString(“C”) + " " + i.Name;

}[/i]

[i]}

}[/i]

}

  1. Second example refer to the sample report template http://www.ayanova.com/Downloads/ReportTemplates/APISampleDispatchingReportwithadditionalRatefieldsbutwithcachedRatepicklist.zip and review its scripts for an example of use. You will also want to refer of course to the http://api.ayanova.com business object library.

This example illustrates a better performing way of doing the above with a cached rate list. This saves time fetching rate info from the database for every record, instead it fetches them all at once up front in the report header and re-uses them later:

in xtraReports1 (header) Before Print

using GZTW.AyaNova.BLL;
using CSLA;

//define the RatePickList so that it is accessible from in the report elsewhere
RatePickList plRates = null;

private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
//now fill the RatePickList (getting all rates - not filtered by region)
plRates = RatePickList.GetList(false);
}

And in its detail band’s Before Print (note change of Fetching the rate from the prefilled picklist)

private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{

object o = DetailReportScheduledUsers.GetCurrentColumnValue(“ID”);

if (o != null)
{
System.Guid g=(System.Guid)o;
//See if it’s empty:
if(g!=Guid.Empty)
{
//now we get the scheduled user object using the id that we got above
//GetDescendant<T> where T is the type of the descendant object
WorkorderItemScheduledUser wis = Workorder.GetDescendant<WorkorderItemScheduledUser>(g);

//below shows displaying properties of that specific scheduled user object - in this case, its Start Date
label4.Text = wis.StartDate.ToString();

//now we want to get the ID of the rate of that scheduled user
//but rate could be empty so only do this if there is actually a rate selected
if (wis.ServiceRateID!=Guid.Empty)
{
//Fetching the rate from the prefilled picklist - the rate selected for that specific scheduled user object
RatePickList.RatePickListInfo i=plRates[wis.ServiceRateID];
//now can access all the properties of this single RatePickListInfo item:
//string RateName=i.Name;
//decimal RateCharge=i.Charge;
//etc etc

label1.Text = i.Name;
label2.Text = i.Charge.ToString();
label5.Text = String.Format(“the charge is: {0} for rate: {1}”, i.Charge.ToString(“C”), i.Name);
label7.Text = i.Charge.ToString(“C”) + " " + i.Name;
}

}
}

}

I imported the sample templates, but the API fields do not contain data when I run the report.

Is there anyway you could just post the script needed to display the rate description so that others can paste it into their reports? That is the only field we need which is holding up using our new reports.

Thank you

Hi Imed

Do note that the Rate Description field IS actually an available field

Also too, the post below does provide an example of the Before Print script that is used in the Detail3 band. Of course, your report would need to be edited with the different scripts in the different areas like the example. And not neccesaarily just copy and paste into another report template as your fields referring to may be called something else (i.e. may be label22 etc). And also too, the example report template displays example of showing the rate’s Name, and the rate’s Charge. You would also need to edit the script for exactly which field you want to show (i.e. refer to api.ayanova.com, view the RatePickList.RatePickListInfo members to make sure calling an actual member name such as i.Description).

These are provided as an example to refer to when creating your own. Don’t forget to address all that identified in the post when editing your report template.

If you would like help with this report template you are creating, export to a file and send directly to support@ayanova.com along with what specfic field in the report is to be filled with the rate Description data (i.e. identify the field by its name in the report template), etc and I would be happy to take a look - Custom-report-templates forum topic outlines what to send (step #3).

  • Joyce