Reporting: Example of using API Methods to display WO Modifier and Modified Date

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.

To receive a quote, please review and provide as per step #3 of forum topic Custom-report-templates

Why we are providing this example:

Open the example Sample Service Workorders Invoiced template from the Service Workorders grid in your report template designer.
Expand the Field List.
As this is a summary type report template, the Field List only displays fields that are also available as columns in the grid.
You will see that Record Modified and Record Modified By are not available datafields.

So if you want to display who last modified a workorder and when, in a summary type report template, you could use API methods to do so as per the example provided

***************

Save As, to create a new copy of the Sample Service Workorders Invoiced template to customize further.

As with the other API examples, declare the namespace at the beginning of Scripts:

using GZTW.AyaNova.BLL;
using CSLA;

Add additional Label controls where needed.
In our example, I added a label2 and label4 in the detailBand1 as well as label controls in the groupHeaderBand2 to identify each with preset text

Add a Before_Print script for the detailBand1 via its properties which automatically adds to the Scripts the following:

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

Edit this script with the following:


private void detailBand1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
//this gets the GUID ID of the workorder itself
Guid gWoID=Workorder.GetIDFromNumber(GetCurrentColumnValue(“LT_O_Workorder”).ToString(), WorkorderTypes.Service);
//this declares the workorder w so we can then work with it
Workorder w =Workorder.GetItemNoMRU(gWoID);
//this displays the data from the Modified of that workorder into the label2 field as text
label2.Text=w.Modified;
//as the Modifier datafield is just the Guid of the user record, need to specifically get that Guid so that can then get the user’s actual first and last name
Guid gUserID=new Guid(w.Modifier.ToString());
User u=User.GetItem(gUserID);
//this displays the first and last name of that specific user from its GUID ID into the label4 field
label4.Text=String.Format("{0} {1}", u.FirstName, u.LastName);
}

Your report controls may be differently named, the workorder fields you want to display may be different. Edit accordingly.