Workorder number padding

I am trying to pad my work order numbers to always show 5 digits. Example… a workorder numbered as 100 would look like 00100 on the report. I can’t seem to get the leading 0’s to show on the report.

The reason for this is I am planning on using the work order number as an invoice number on the form but want the data to look like this:

Workorder #: 100
Invoice #: I00100

Any help would be appreciated.

Thx,
Steve

Hi Steve

If want to pad zeros that would require a C# script to determine what the datafield’s length is (in this case the workorder number object), and set what the length would be so that if less then five to pad zeros to the left of it and is a maximum of five characters in length.

If not familiar with C# scripting, a suggestion is to search online as well as through the existing report templates and reporting section of this forum for what you want to do with C# for examples used elsewhere that you can then refer to when creating your own. I myself too would search online for examples if I was to do this for you, trying out with a copy of the report template, trying different scripts etc till it worked how I wanted.

For example, to pad just zero’s, through searching would find url’s such as http://bytes.com/topic/c-sharp/answers/443581-string-format-padding-zeros and from that would try until got something like:

private void xrLabel1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
decimal WOstring;
WOstring =Convert.ToDecimal(DetailReport.GetCurrentColumnValue(“LT_O_Workorder”));
label1.Text = String.Format("{0:00000}", WOstring);
}

Or something like:

private void label2_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
label2.Text = DetailReport.GetCurrentColumnValue(“LT_O_Workorder”).ToString().PadLeft(5, ‘0’);
}

Both would have the output to 5 numbers long, with leading zeros.

And then if would want a character in the very beginning, then just add it as you would any text you want to show regardless as per other examples in for example the Sample Detailed Service Workorder with Grand Total which includes prefixing what is shown in the subject line if auto emailed from the print preview, or what is showned for the custom script for the physical city, state and postal code:

label3.Text = “I” + (DetailReport.GetCurrentColumnValue(“LT_O_Workorder”).ToString().PadLeft(5, ‘0’));

Above is a no charge example to get you started. Anything further I can certainly provide custom report template design and scripting for you - just export your report template to file, and email to support@ayanova.com along with details on what you want done and I can provide a quote. See also forum topic Custom-report-templates

  • Joyce

Thanks Joyce,

I guess now is the time to add C# to my skills! lol. I was hoping it would be as easy as applying a format string function like is available in most apps. I appreciate you getting me started with the sample code. Looks very similar to C++ code so I am hoping the learning curve isn’t too high!.

Steve