CRM Open Source Business & Social CRM Software

Results 1 to 10 of 10

Thread: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

  1. #1
    dant is offline Member
    Join Date
    Feb 2009
    Posts
    12

    Default How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    Hello everybody,
    This article discusses how to create a Custom Field to consume StrikeIron ZIP Code Information within SugarCRM Account EditView.

    Whenever an Account Detail record is created or edited, one always wonders if a ZIP code/Postal code is correct or not, and how we can identify the location of our customers using this ZIP/Postal code. This can be achieved with StrikeIron's ZIP Code Information Web Service. Using this Web service, you can retrieve the City, County, State name of any customer's ZIP code in real-time.

    - Prerequisites:
    1. Sugar CRM 5.2 or later
    2. Enhanced Studio 2.2.1 or later.
    The steps
    In general, we have 4 steps to complete this sample:
    1. Create "Custom Code field" for a Sugar Accoun. When this step is completed, you will have a button called "Verify Postal Code" that will help to verify a ZIP/Postal code of a customer.
    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 have been installed into your SugarCRM.
    Download the latest version 2.2.1 Demo from this web site, then use Module Loader in Admin page to upload and install this module to Sugar CRM. This module will allow you to create a custom "CODE" field, where you can put your php code into the value of this field.

    Step 1 - Create Custom Code field.

    Navigate to Admin -> Developer Tools>Studio. In Modules tree, drop down Accounts node, choose Fields>Add Fields.
    Select "COde" for Data Type value, enter SIZIPChecker for field name, SI ZIP Checker for Display label.

    Enter the following code to Code text value:

    PHP Code:
    echo '
    <script>
    function invoke() {
       alert("Progress started");
        var callback = {
            success: function(o) {
            
                document.getElementById("div_info").innerHTML = 
                    o.responseText;
            }
        }
        
        var connectionObject = YAHOO.util.Connect.asyncRequest ("GET", "/sugarcrm/sizipcode.php?zipcode='
    .$bean->billing_address_postalcode.'" , callback);
    }
    </script>  
    <div style="align:left">
    <input type="button" id="botton" name="button" value="Verify postal code" onclick="invoke();"></div>

    <div id="div_info">
    </div>
    '

    This php code will help create a button called "Verify Postal Code". When user click on it, it will use a php page: "/sugarcrm/sizipcode.php" to consume the StrikeIron ZIP Code Information web services for some location info.

    Step 2 - Determine where to place above button
    We decided to place it to the Account EditView, the place where user can edit a Account detail information like Name, billing address, shipping address...
    Navigate to Layout on the same tree, drop down the nodes, find EditView node, click on it. Drag the "New Row" to Address Information, below Billing Street. We would like the user to see this button near the billing postal code. Then drag the SIZIPChecker field to this empty panel. Click Save and Deploy.

    Step 3 - Create a Web service client as a php page.

    Create a file named "sizipcode.php", edit the file with the following code, and copy it to SugarCRM root folder (like E:\Program Files\sugarcrm-5.2.0\htdocs\sugarcrm):

    PHP Code:
    <?php
    $handle 
    fopen('http://wslite.strikeiron.com/zipcodeinfolite01/ZIPCodeInfoLite.asmx/GetZIPCodeInfo?ZIPCode='$_REQUEST['zipcode'], "rb");
    $contents '';
    while (!
    feof($handle)) {
        
    $contents .= fread($handle8192);
    }
    fclose($handle);

    $s simplexml_load_string($contents); 


    echo 
    '<div>ZIP code information:</div>
    <div id="div_info"><b>Result</b>:'
    .$s->ServiceStatus->StatusDescription.'
    <br><b>City: </b>'
    .$s->ServiceResult->ZIPCodes->ZIPCodeData->PreferredCityName.'</b>
    <br><b>State: </b>'
    .$s->ServiceResult->ZIPCodes->ZIPCodeData->State.'</b>
    <br><b>County: </b>'
    .$s->ServiceResult->ZIPCodes->ZIPCodeData->County.'</b>
    </div>'
    ;  

    ?>
    In this code, we would like to consume the StrikeIron Web service lite at http://wslite.strikeiron.com/zipcode...eInfoLite.asmx , and return the Zipcode information 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 Postal code button. Click on it to verify the postal code of this customer.
    Have fun!

    References
    1. StrikeIron ZIP Code Information Web service:
    2. StrikeIron web services lite
    Attached Files Attached Files
    Last edited by dant; 2009-03-12 at 05:29 AM.

  2. #2
    dolphinlike is offline Member
    Join Date
    Jun 2009
    Posts
    8

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    Hi guys
    what am I going to do?
    1.add a customized button in a Account module , the way I followed :How to consume ZIP Code Information Web service from StrikeIron within SugarCRM
    2.click the button, invoke the webservice method:GetZIPCodeInfo in http://wslite.strikeiron.com/zipcode...Lite.asmx?wsdl

    how to repeat the problem I met?
    - Prerequisites:
    1. Sugar CRM 5.2 or later
    2. Enhanced Studio 2.2.1 or later.
    The steps
    In general, we have 4 steps to complete this sample:
    1. Create "Custom Code field" for a Sugar Accoun. When this step is completed, you will have a button called "Verify Postal Code" that will help to verify a ZIP/Postal code of a customer.
    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 have been installed into your SugarCRM.
    Download the latest version 2.2.1 Demo from this web site, then use Module Loader in Admin page to upload and install this module to Sugar CRM. This module will allow you to create a custom "CODE" field, where you can put your php code into the value of this field.

    Step 1 - Create Custom Code field.

    Navigate to Admin -> Developer Tools>Studio. In Modules tree, drop down Accounts node, choose Fields>Add Fields.
    Select "COde" for Data Type value, enter SIZIPChecker for field name, SI ZIP Checker for Display label.

    Enter the following code to Code text value:
    PHP Code:
    Code:
    echo '
    <script>
    
    var xmlhttp;
    
    function invoke() {
       alert("Progress started");
    
    
    	xmlhttp=GetXmlHttpObject();
    	if (xmlhttp==null)
    	  {
    	  alert ("Your browser does not support XMLHTTP!");
    	  return;
    	  }
    	var url="index.php?entryPoint=sizipcode?zipcode='.$bean->billing_address_postalcode.'";
    	alert("url="+url);
    	xmlhttp.onreadystatechange=stateChanged;
    	xmlhttp.open("GET",url,true);
    	xmlhttp.send(null);
    
    }
    
    
    function stateChanged()
    {
    if (xmlhttp.readyState==4)
      {
      document.getElementById("div_info").innerHTML=xmlhttp.responseText;
      }
    }
    
    function GetXmlHttpObject()
    {
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
      }
    if (window.ActiveXObject)
      {
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
      }
    return null;
    }
    
    </script>  
    <div style="align:left">
    <input type="button" id="botton" name="button" value="Verify postal code" onclick="invoke();"></div>
    
    <div id="div_info">
    </div>
    ';
    This php code will help create a button called "Verify Postal Code". When user click on it, it will use a php page: "/sugarcrm/sizipcode.php" to consume the StrikeIron ZIP Code Information web services for some location info.
    please add this line :
    Code:
    'sizipcode' => array('file' => 'sizipcode.php', 'auth' => true)
    , in sugarcrm-5.2.0e\htdocs\sugarcrm\include\MVC\Controller\entr y_point_registry.php .( this line resolves "Not A Valid Entry Point" problem)

    Step 2 - Determine where to place above button
    We decided to place it to the Account EditView, the place where user can edit a Account detail information like Name, billing address, shipping address...
    Navigate to Layout on the same tree, drop down the nodes, find EditView node, click on it. Drag the "New Row" to Address Information, below Billing Street. We would like the user to see this button near the billing postal code. Then drag the SIZIPChecker field to this empty panel. Click Save and Deploy.

    Step 3 - Create a Web service client as a php page.

    Create a file named "sizipcode.php", edit the file with the following code, and copy it to SugarCRM root folder (like E:\Program Files\sugarcrm-5.2.0\htdocs\sugarcrm):

    PHP Code:
    Code:
    <?php
    	require_once('include/nusoap/nusoap.php');
    	$client = new soapclient('http://wslite.strikeiron.com/zipcodeinfolite01/ZIPCodeInfoLite.asmx?wsdl',true);
    
    
    	$aryPara = array('ZIPCode'=> $_REQUEST['zipcode']);
    
    	$return = $client->call('GetZIPCodeInfo',$aryPara);
    	
    
    echo '<div>ZIP code information:</div>
    <div id="div_info"><b>Result</b>:'.$return['GetZIPCodeInfoResult']['ServiceStatus']['StatusDescription'].'
    <br><b>City: </b>'.$return['GetZIPCodeInfoResult']['ServiceResult']['ZIPCodes']['ZIPCodeData']['PreferredCityName'].'</b>
    <br><b>State: </b>'.$return['GetZIPCodeInfoResult']['ServiceResult']['ZIPCodes']['ZIPCodeData']['State'].'</b>
    <br><b>County: </b>'.$return['GetZIPCodeInfoResult']['ServiceResult']['ZIPCodes']['ZIPCodeData']['County'].'</b>
    </div>';   
    
    ?>
    after I click the "Verify postal code" button , it retruns me the website of sugarcrm, which is wrong. That is the problem I met, if you know what is wrong with my code, plz tell me, thanks
    Attached Images Attached Images  

  3. #3
    dant is offline Member
    Join Date
    Feb 2009
    Posts
    12

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    Hi Dolphinlike,

    Look at the code:

    PHP Code:
           var url="index.php?entryPoint=sizipcode?zipcode='.$bean->billing_address_postalcode.'";
        
    alert("url="+url); 
    In order to call to the right php page, I think you should try the following Url instead:
    PHP Code:
           var url="/sugarcrm/sizipcode.php?zipcode='.$bean->billing_address_postalcode.'" ;
           ... 
    Notice that the /sugarcrm is the root web folder of SugarCRM on your server. The reason why SugarCRM forwards the response to admin page is that it does not understand your entryPoint definition or the Url is invalid.


    Hope it helps.
    Dan

  4. #4
    dolphinlike is offline Member
    Join Date
    Jun 2009
    Posts
    8

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    Hi Dant
    thanks for you reply!
    I've tried "var url="/sugarcrm/sizipcode.php?zipcode='.$bean->billing_address_postalcode.'" ;" but it didn't work.

  5. #5
    dant is offline Member
    Join Date
    Feb 2009
    Posts
    12

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    Hi,

    I just figured it out a thing: when you put
    require_once('include/nusoap/nusoap.php');

    into your sizipcode.php code, the page could not return you anything but invalid page error. This means your php code in this file does not seem to work with SugarCRM. In this topic, I used the fopen php function, that does need to use any soap library, so the page return the result.

    You can test the sizipcode.php url independently (in the browser) first to make sure it works with sugarcrm before calling it from Custom field -Code

    One more thing, I tried to remove the line 'sizipcode' => array('file' => 'sizipcode.php', 'auth' => true) from the entry_point_registry.php file, the sizipcode.php still works in case there are no nusoap calls in the file.

    Hope that helps
    Dan

  6. #6
    dolphinlike is offline Member
    Join Date
    Jun 2009
    Posts
    8

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    dant
    thank you! you are really a nice guy. my skype id is :dolphinlikelr. I am a java developer and I am from china Wish we could be a good friend. my email: dolphinlike@163.com

  7. #7
    dant is offline Member
    Join Date
    Feb 2009
    Posts
    12

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    In my previous reply, I just pointed out where is the problem.
    So in case you want to use nusoap in SugarCRM, there are lots of things to do.
    I tried to modify your sizipcode.php code a litle bit like this:
    PHP Code:
    <?php
        define
    ('sugarEntry'TRUE); 
        require_once(
    'include/nusoap/nusoap.php');
        
    $client = new nusoapclient('http://wslite.strikeiron.com/zipcodeinfolite01/ZIPCodeInfoLite.asmx?wsdl',true);

        echo 
    $_REQUEST['zipcode'];
        
    $aryPara = array('ZIPCode'=> $_REQUEST['zipcode']);

        
    $return $client->call('GetZIPCodeInfo',array($aryPara));
        

    echo 
    '<div>ZIP code information:</div>
    <div id="div_info"><b>Result</b>:'
    .$return['GetZIPCodeInfoResult']['ServiceStatus']['StatusDescription'].'
    <br><b>City: </b>'
    .$return['GetZIPCodeInfoResult']['ServiceResult']['ZIPCodes']['ZIPCodeData']['PreferredCityName'].'</b>
    <br><b>State: </b>'
    .$return['GetZIPCodeInfoResult']['ServiceResult']['ZIPCodes']['ZIPCodeData']['State'].'</b>
    <br><b>County: </b>'
    .$return['GetZIPCodeInfoResult']['ServiceResult']['ZIPCodes']['ZIPCodeData']['County'].'</b>
    </div>'
    ;  
        
    ?>
    Here you can see some new changes:
    1. I add define entry point to make this url valid
    2. your $client instance is nusoapclient, not soapclient as you did.
    3. the $client->call changed, you can see the parameter now is array($anyPara) , not only $anyPara as before.

    It works for now. Now try with other Web services from http://www.strikeiron.com to double check it.
    Enjoy.
    Dan

  8. #8
    dolphinlike is offline Member
    Join Date
    Jun 2009
    Posts
    8

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    thanks, Dant

  9. #9
    kevin85 is offline Junior Member
    Join Date
    Jun 2010
    Posts
    2

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    hey, finally found the solution after searching for more than 2hours. thanks for the code.

  10. #10
    joshr1124 is offline Junior Member
    Join Date
    Jun 2011
    Posts
    1

    Default Re: How to consume ZIP Code Information Web service from StrikeIron within SugarCRM

    Quote Originally Posted by dolphinlike View Post
    dant
    thank you! you are really a nice guy. my skype integration id is :dolphinlikelr. I am a java developer and I am from china Wish we could be a good friend. my email: dolphinlike@163.com
    I have some questions about java. can i contact you through skype too?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Is the SugarCRM Web Service really that slow?
    By timothyp in forum General Discussion
    Replies: 15
    Last Post: 2010-12-15, 05:37 PM
  2. Replies: 5
    Last Post: 2009-03-05, 04:41 PM
  3. Replies: 0
    Last Post: 2009-02-18, 09:16 AM
  4. Replies: 1
    Last Post: 2009-02-06, 09:53 PM
  5. Using SugarCRM for cutomer service chat?
    By JimFitz in forum General Discussion
    Replies: 1
    Last Post: 2007-07-03, 11:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •