Keeping Address Street Data Clean

Keeping addresses clean in the system is important. It is a common problem for users to press enter in the the address street which will cause blank lines to occur in the address output. In bad cases, if a user presses the enter multiple times or accidentally holds down the enter button, can result in some very strange looking addresses.


Address Line 1
Address Line 2
.
.
.
.
.
.
City, State, Zip Code

This kind of address will cause problems on external documents, causing addresses to not display correctly in windowed envelopes or in many cases would simply not show the city, state and zip code as these will exceed the display window on the report.

This type of problem can be handled in code, either on the form where addresses are entered, or the table if you need to ensure data imported from external systems are clean.

If you want to modify the form for data entry, then you need to open the form LogisticsPostalAddress, then open the data sources and expand the table LogisticsPostalAddress, then the fields, and find field Street. On the methods under the field, right click and override method modified. Modify the method to look like below:

public void modified()
{
while (substr(LogisticsPostalAddress.Street, strlen(LogisticsPostalAddress.Street),1) == “\n”)
{
LogisticsPostalAddress.Street = substr(LogisticsPostalAddress.Street, 1, strlen(LogisticsPostalAddress.Street) -1);
}

super();
}

This code will look to check if the last character entered is a return, if so it will remove it. It will continue to do this until there are not more returns at the end of the street address.

We can enhance this further by changing the code like below:

public void modified()
{
while
(
(substr(LogisticsPostalAddress.Street, strlen(LogisticsPostalAddress.Street),1) == “\n”)
|| (substr(LogisticsPostalAddress.Street, strlen(LogisticsPostalAddress.Street),1) == ” “)
)
{
LogisticsPostalAddress.Street = substr(LogisticsPostalAddress.Street, 1, strlen(LogisticsPostalAddress.Street) -1);
}

super();
}

The above code adds an additional control to look for spaces at the end of the street address. It is possible that a user can also enter a combination of returns and spaces, both cause unnecessary padding and can cause blank lines to occur. If the user enters return space, then without this enhancement the address would still have a blank line.

The above code works well for user data entry, but it you want to ensure all street addresses include this control then you need to place the following code on the table LogisticsPostalAddress, under the methods, open method modifiedfield:

Search for the case fieldNum(LogisticsPostalAddress, Street): and replace the code to look like the below:

case fieldNum(LogisticsPostalAddress, Street):

while
(
(substr(this.Street, strlen(this.Street),1) == “\n”)
|| (substr(this.Street, strlen(this.Street),1) == ” “)
)
{
this.Street = substr(this.Street, 1, strlen(this.Street) -1);
}

this.formatLogisticsAddressNL();
this.LogisticsPostalAddressMap::modifiedField(_fieldId);
break;

As with all code, please ensure you test this works for you, before releasing code into a production environment.

Advertisements

One thought on “Keeping Address Street Data Clean

  1. Phil C says:

    Thanks for this. My dilemma is that I am trying to correct a lot of street addresses that already have spaces in them via a DBU. The DBU will update the table, but the view still has the space. Do you have a method to fix this when I run a DBU?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s