Reporting: Example of using API Methods to display PO vendor and client data

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 Purchase Order Detailed Report template in the report template designer
Click on xrLabel19 in the designer panel, and view the Field List so you can see at a quick glance where bound to (you can also expand the Data Bindings Text for this and you will also see it is bound to LT_Contact_Label_FullContact)

In a detailed report for a PO, the report datafields do not include specific phone1, phone 2, street, city, state, etc fields for the vendor, nor for the client

So if you want to display the vendor address in a specific way instead of using the existing FullContact, you could use API methods to do so as per the example provided

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

  1. Download the example API method report template http://www.ayanova.com/Downloads/ReportTemplates/APIScriptVendorAddressSamplePurchaseOrderDetailedReport.zip
  2. Extract
  3. Import as per http://www.ayanova.com/AyaNova7webHelp/importing_a_report_template.htm
  4. Open in the report template designer

This report template is a further customization of the existing Sample Purchase Order Detailed Report template that you can use as is or further customize or refer to when creating/customizing your own.

  1. You will see additional fields label1, label2, label3, label5, label6 have been added (and their background property set to colors so they are easy to pick out)

  2. And that the previous fields xrLabel19(that was bound to the vendor’s FullContact datafield), xrLabel18(that was bound to the vendor’s FullAddress datafield)
    , and xrLabel17 (that was bound to the clients FullAddress datafield) have been removed.

  3. Via Scripts you will see that the namespace has been declared in the Before Print for the whole report in xtraReport1 to save typing:

using GZTW.AyaNova.BLL;
using CSLA;

  1. And that the Detail band for the DetailReport has had a BeforePrint script added to get the actual PO object, get its vendor and display its individual address and contact fields as specified, and get its drop to client if present and display its individual address fields as specified.

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

//1. create variable called POID and assigning the value of the report field for the LT_Purchaseorder_label_id)
//cause need to know this value to be able to GetItem (in step 2)
System.Guid POID=(System.Guid)DetailReport.GetCurrentColumnValue(“LT_PurchaseOrder_Label_ID”);

//2. //get the actual PO***object directly and declare it as the purchaseorder oject poo in preparation of the
//other following steps because we will need it at three times: once for the vendor’s contact, another time for the vendor’s address
//AND***to get the client address fields
PurchaseOrder poo = PurchaseOrder.GetItem(POID);

//3. Now get the contact data using the poo
//rather than getting the vendor every time need to get the phone1, the phone2, declare the vendor so can use
Vendor vo = Vendor.GetItem(poo.VendorID);
label1.Text = string.Format("{0} {1} {2} {3} {4}", vo.Phone1, " ", vo.Phone2, " ", vo.Email);

// 4. Now get the address data also from this vendor object
//we would NOT***want to write out getting the actual vendor object using Vendor.GetItem(PurchaseOrder.GetItem(POID).VendorID);
//instead we would just get it via the already GetItem vo

//the postal Address fields are within the MailToAddress instead of directly off of the vo
// get vendor oject ->***then gets the mailtoaddress of that vendor oject as that is where the address fields (i.e. city, etc)
Address va = vo.MailToAddress;

label2.Text = string.Format("{0} {1} {2} {3} {4}", va.DeliveryAddress, " “, va.City, " “, va.StateProv);
label3.Text = string.Format(”{0} {1} {2}”, va.Postal, " ", va.Country);

//similiar also for getting the client address
//EXCEPT***that there is a possiblity of NO***Client being dropped shipped to
//so need to have if / else statement in the event the Guid is empty for the Drop to client

if (poo.DropShipToClientID != Guid.Empty)
{
//set these fields to visible
xrLabel1.Visible=true;
label5.Visible=true;
label6.Visible=true;

//as with the vendor, declare the MailToAddress for the client object as ca
Address ca = Client.GetItem(poo.DropShipToClientID).MailToAddress;

//what to show in these fields
label5.Text = string.Format("{0} {1} {2} {3} {4}", ca.DeliveryAddress, " “, ca.City, " “, ca.StateProv);
label6.Text = string.Format(”{0} {1} {2}”, ca.Postal, " ", ca.Country);

}
else
{
//this states that if the client Guid is empty to set the fields to not be visible
xrLabel1.Visible=false;
label5.Visible=false;
label6.Visible=false;
}

}
[/i]