Hello everybody,
Working with your Account, Contact, and custom addresses, wouldn't it be nice if there was a way to verify addresses are correct and actually exist according to the United States Post Office official data? This way, when sending collateral, products, or anything, you can save money by ensuring that it actually gets there, have much better data, and ultimately provide much better customer service. There is nothing more harmful to CRM efforts than incorrect and/or incomplete customer information.
Fortunately, address verification (and many other types of verification) can easily be integrated into SugarCRM. This topic discusses a way that can help you to verify those addresses within SugarCRM using US Address Verification Web Service 5.0.0 from StrikeIron.
- Prerequisites:
1. Sugar CRM 5.2 or later
2. Enhanced Studio 2.2.1 or later.
The steps
In general, we got 4 steps to complete this sample:
1. Create "Custom Code field" for a SugarCRM Account. When this step is completed, you will have a button called "Verify Address" that will help to verify the billing address of any customers.
2. Layout the position of this button using Studio tool for developer in Sugar CRM
3. Create a Sugar php page to consume the StrikeIron Web service.
4. Run the sample
Before starting with the 4 steps above, you have to make sure the Enhanced Studio has been installed into SugarCRM.
Download the latest version Demo 2.2.1 , then use Module Loader in Admin page to upload and install this module to Sugar CRM. This installation allows you to create a custom "CODE" field, where you can put your php code into Account EditView.
Step 1 - Create Custom Code field.
Navigate to Admin -> Developer Tools ->Studio. In the Modules tree, drop down Accounts node, choose Fields ->Add Fields.
Select "Code" for Data Type value, enter "SIAddressChecker" for field name, "SI Address Checker" for Display label.
Enter the following code to the Code text value:
This php code helps to create a button called "Verify Address". When a user clicks on it, it will send a request to a php page "/sugarcrm/siusaddress.php" to consume the StrikeIron US Address Verification web service. You will create this page in step 3.PHP Code:$address = str_replace("\r\n","|",$bean->billing_address_street); //to remove the carrage return and line feed characters of from address value with 2 lines.
echo '
<script>
function invokeAddress() {
alert("Progress started");
var callback = {
success: function(o) {
document.getElementById("div_address").innerHTML = o.responseText;
}
}
var addr = "'.$address.'";
var ar = addr.split("|");
if (ar.length >1)
{
strConn = "/sugarcrm/siusaddress.php?address1=" + ar[0] + "&address2=" + ar[1] + "&citystatezip='.$bean->billing_address_city.' '.$bean->billing_address_state.' '.$bean->billing_address_postalcode.' ";
} else
{
strConn = "/sugarcrm/siusaddress.php?address1="+ ar[0]+"&address2=&citystatezip='.$bean->billing_address_city.' '.$bean->billing_address_state.' '.$bean->billing_address_postalcode.' ";
}
alert( strConn);
var connectionObject = YAHOO.util.Connect.asyncRequest ("GET", strConn, callback);
}
</script>
<div style="align:left">
<input type="button" id="btn" name="button" value="Verify address" onclick="invokeAddress();"></div>
<div id="div_address">
</div>
';
Step 2 - Determine where to place the button
The best place to put it is the Account EditView, the place where user can edit a Account detail information (Name, billing address, shipping address...).
So, navigate to Layout on the same tree (in Studio tool), drop down the nodes, find EditView node, click on it. Drag the "New Row" to Address Information, below Billing Street. It is a good idea to have this button physically near the billing address. Then, drag the SIAddressChecker field to this empty panel. Click Save and Deploy.
Step 3 - Create a Web service client as a php page.
Create a file named "siusaddress.php", edit the file with the following code, and copy it to SugarCRM root folder (i.e.: E:\Program Files\sugarcrm-5.2.0\htdocs\sugarcrm):
-- Notes: you have to replace the username and password values with the ones you have afterPHP Code:<?php
$siurl = 'http://ws.strikeiron.com/StrikeIron/USAddressVerification5/USAddressVerification/VerifyAddressUSA?LicenseInfo.RegisteredUser.UserID=hoaidan@yahoo.com&LicenseInfo.RegisteredUser.Password=0503danth&VerifyAddressUSA.AddressLine1="'.urlencode($_REQUEST['address1']).'"&VerifyAddressUSA.AddressLine2="'.urlencode($_REQUEST['address2']).'"&VerifyAddressUSA.CityStateZIPCode="'.urlencode($_REQUEST['citystatezip']).'"';
print($siurl);
$handle = fopen($siurl, "r");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$s = simplexml_load_string($contents);
echo '<div>Address verification result:</div>
<div id="div_info"><b>Address status</b>:'.$s->VerifyAddressUSAResponse->VerifyAddressUSAResult->ServiceStatus->StatusDescription.'
<br><b>RemainingHits: </b>'.$s->SubscriptionInfo->RemainingHits.'</b>
<br><b>Address Line 1: </b>'.$s->VerifyAddressUSAResponse->VerifyAddressUSAResult->ServiceResult->AddressLine1.'</b>
<br><b>Address Line 2: </b>'.$s->VerifyAddressUSAResponse->VerifyAddressUSAResult->ServiceResult->AddressLine2.'</b>
<br><b>City: </b>'.$s->VerifyAddressUSAResponse->VerifyAddressUSAResult->ServiceResult->City.'</b>
<br><b>State: </b>'.$s->VerifyAddressUSAResponse->VerifyAddressUSAResult->ServiceResult->State.'</b>
<br><b>ZIP: </b>'.$s->VerifyAddressUSAResponse->VerifyAddressUSAResult->ServiceResult->ZIPCode.'</b>
<br><b>Latitude: </b>'.$s->VerifyAddressUSAResponse->VerifyAddressUSAResult->ServiceResult->GeoCode->Latitude.'</b>
<br><b>Longitude: </b>'.$s->VerifyAddressUSAResponse->VerifyAddressUSAResult->ServiceResult->GeoCode->Longitude.'</b>
</div>';
?>
StrikeIron user registration.
In this code, we would like to consume the StrikeIron US Address Verification Web service at "http://ws.strikeiron.com/USAddressVerification4_0?WSDL" , and return the modified Address to Account EditView page. The call is nothing but a HTTP GET request to the Web service.
Step 4- Run the sample
Open Account list, edit one of them, you can see the "Verify Address" button. Click on it to verify the billing address of this customer.
That's all there is to it. You can modify the "Custom Code" to display the verification result on a floating <div> so that you can easily move it when editing the Account detail.
Hope it helps
Have fun!
Dan Tong.
References
1. StrikeIron US Address Verification 5.0.0 Web service:
2. SugarCRM Enhanced Studio


LinkBack URL
About LinkBacks



Reply With Quote


Bookmarks