Scripts to display custom field as currency, and not show at all if blank

Here is a custom sample report template that provides some different types of scripting. This custom report template is based ona collaboration between myself and an Electrician company that uses AyaNova.

One script is based on the AyaNova v3 Manual tutorial “Converting a custom field to display as a currency value” starting page 696

Sample Parts Custom To Currency and Blanks

This report template includes scripts to display a custom currency field as currency in a report template, and also includes scripts to not display fields that have a price of $0.00 (a suggestion for possible use - so that the user can manually pencil in the amounts to enter at a later time on the printed copy). Parts display grouped by Category, with a new category starting a new page.

This report template, once imported, would be availalbe from the Parts grid in the INventory navigation pane.

This report assumes that you have enabled the following custom fields for the Part entry screen

Custom0 as a text field
Custom1 as a text field
Custom3 as a currency field
Because Custom3 is a custom field - it by default always displays in a report as a string (as text) even though in the Custom field editor you have selected currency. This is because as it is possible for you to easily change the currency format to a different format, the data in the custom field has to be saved in the database as a string.

When you want to display a custom field in a report, it will therefore by default always display as a string.

Selecting a FormatString for a custom field will not apply the format, because the string property won’t accept it.

You have to enter a script to change the data from a string to a decimal, and than have that decimal display formated for currency.

To do this we open the Properties tab for the field (in this case xrLabel12), expand Scripts and open the OnBeforePrint script to edit

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

//this gets the value of the custom field, and displays it in field xrLabel12 in currency format
decimal d;
decimal.TryParse(DetailReport.GetCurrentColumnValue(“LT_Part_Label_Custom3”).ToString(),out d);
xrLabel12.Text= d.ToString(“c”);

//this states that if the Custom3 is empty (whichis “”), to set the field xrLabel12 to not be visible


Note the second part of the script - which sets that if the datafield for Custom3 is empty “”, the Visible property of the field xrLabel12 = false - which means xrLabel12 won’t be visible.

Now open the Properties tab for the xrLabel13 field (Cost), expand the Scripts, and open the OnBeforePrint script

Because Cost is saved within the database as a number, this script actually specifically states if not equal to 0

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

//this states that if the Cost is 0, to set the field xrLabel13 to not be visible


Same also with the OnBeforePrint script for xrLabel14 (Retail)

This report template is grouped by the Part Category. To do this, select the GroupHEader1 band, and select Properties.
Now select the GroupFields property, and open the Collection
You will see that there is one GroupField set up - which is the LT_O_PartCategory in a descending SortORder

And as this report template also wants a new grouping to start on a new page, the PageBreak property is set to BeforeBand, so that a new group starts on a new page.

Again, with all sample report templates, I encourage you to customize further, editing to your needs - or use to refer to when customizing and creating your own.

The above download sample report template Sample Custom To Currency and Blankson this date has been replaced so that it will be compliant with the new version of the printing design and engine component that we will be releasing with the next maintenance update of AyaNova guess-timated to be released late Dec/ early Janurary.

If you had previously downloaded the sample report template above, do remove it (via Administration -> Report Templates) and download this new replacement via Sample Custom To Currency and Blanks