This article will show how to develop a Cloud View (a Connector in Sugar CRM 5.2) which will consume the Strike Iron Cortera Service at http://wslite.strikeiron.com/Cortera...Lite.asmx?WSDL. More information about this Web service
There are 5 steps to get the sample work.
Step 1 – Determine the component name
This name will be used to define the name of a Cloud View. In this sample, we call it “strikeiron” .
Step 2 – Prepare the empty text files and directory to program the sample:
We need to create the following directory structure:
Directory Files
[root]/formatters - strikeiron.php
[root]/formatters/tpls - default.tpl, strikeiron.gif (image icon file)
[root]/language - en_us.lang.php
[root]/source / - config.php, mapping.php, strikeiron.php, vardefs.php
Step 3 – Start programming
1. Edit file: formatters\strikeiron.php.
In this class, the getIconFilePath() operation returns the path of deployed CloudView icon.PHP Code:<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/connectors/formatters/default/formatter.php');
class ext_soap_strikeiron_formatter extends default_formatter {
public function getDetailViewFormat() {
$mapping = $this->getSourceMapping();
$mapping_name = !empty($mapping['beans'][$this->_module]['name']) ? $mapping['beans'][$this->_module]['name'] : '';
if(!empty($mapping_name)) {
$this->_ss->assign('mapping_name', $mapping_name);
return $this->fetchSmarty();
}
$GLOBALS['log']->error($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']);
return '';
}
public function getIconFilePath() {
return 'modules/Connectors/connectors/formatters/ext/soap/strikeiron/tpls/strikeiron.gif';
}
}
?>
2. Edit template of CloudView (formatters\tpls\default.tpl):
STRIKEIRON_LINK will be defined in below step.PHP Code:<div style="visibility:hidden;" id="strikeiron_popup_div"></div>
<script src="" type="text/javascript"></script>
<script type="text/javascript" src="{sugar_getjspath file='include/connectors/formatters/default/company_detail.js'}"></script>
<script type="text/javascript">
function show_ext_soap_strikeiron(event)
{literal}
{
var xCoordinate = event.clientX;
var yCoordinate = event.clientY;
var isIE = document.all?true:false;
if(isIE) {
xCoordinate = xCoordinate + document.body.scrollLeft;
yCoordinate = yCoordinate + document.body.scrollTop;
}
{/literal}
cd = new CompanyDetailsDialog("strikeiron_popup_div", '<div id="strikeiron_div"><div>Company found:</div><iframe id="resFrame" src="" width="90%" height="110"> </iframe><div><a href="http://www.strikeiron.com/ProductDetail.aspx?p=409">About StrikeIron Cortera Service</a></div><div><a href="http://www.strikeiron.com/Register.aspx">Register</div>', xCoordinate, yCoordinate);
cd.setHeader("{$fields.{{$mapping_name}}.value}");
cd.display();
var sugarValue = "{$fields.{{$mapping_name}}.value}";
var sugarValues = sugarValue.split(" ");
var sugarCoName = "";
{literal}
for (i=1; i< sugarValues.length; i++)
{
sugarCoName = sugarCoName + sugarValues[i-1] + " ";
}
{/literal}
var url = "{{$config.properties.STRIKEIRON_LINK}}?Company=" + sugarCoName;
document.getElementById('resFrame').src = url;
{literal}
}
{/literal}
</script>
3. Edit config.php file
Notes: $config.properties.STRIKEIRON_LINK is the value of StrikeIron Cortera Link you need to set in Connector Settings configuration step in step 6PHP Code:<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
// created: 2008-10-03 14:31:59
$config = array (
'name' => 'StrikeIronŠ',
'properties' =>
array (
'STRIKEIRON_LINK' => 'http://a.server.com/sisugar.aspx',
),
);
?>
4. Edit strikeiron.php file
5. Edit mapping.php filePHP Code:<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/connectors/sources/ext/soap/soap.php');
class ext_soap_strikeiron extends ext_soap {
public function __construct(){
parent::__construct();
$this->_enable_in_wizard = false;
$this->_enable_in_hover = true;
}
public function getItem($args=array(), $module=null){}
public function getList($args=array(), $module=null){}
public function __destruct(){
parent::__destruct();
}
}
?>
6. Edit vardefs.php filePHP Code:<?php
// created: 2009-01-22 21:40:15
$mapping = array (
'beans' =>
array (
'Accounts' =>
array (
'name' => 'name',
'id' => 'id',
),
),
);
?>
7. Edit language file: en_us.lang.phpPHP Code:<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
$dictionary['ext_soap_strikeiron'] = array(
'comment' => 'vardefs for StrikeIron connector',
'fields' => array (
'id' =>
array (
'name' => 'id',
'vname' => 'LBL_ID',
'type' => 'id',
'comment' => 'Unique identifier',
'hidden' => true,
),
'name'=> array(
'name' => 'name',
'vname' => 'LBL_NAME',
'type' => 'varchar',
'hover' => true,
'comment' => 'The name of the company',
),
)
);
?>
Step 4 – Deploy the filesPHP Code:<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
$connector_strings = array (
//licensing information shown in config screen
'LBL_NAME' => 'Company Name',
//Configuration labels
'STRIKEIRON_LINK' => 'StrikeIron Cortera Link',
);
?>
Copy the source file to SugarCRM application folder:
formatters/strikeiron.php -copy to---> [sugarcrm_root_dir]/ htdocs\sugarcrm\modules\Connectors\connectors\form atters\ext\soap\strikeiron
All files in formatters/tpls/ -copy to---> [sugarcrm_root_dir]\ htdocs\sugarcrm\modules\Connectors\connectors\form atters\ext\soap\strikeiron\tpls
All files in /source --copy to--> [sugarcrm_root_dir]\ htdocs\sugarcrm\modules\Connectors\connectors\sour ces\ext\soap\strikeiron\
All files in /language -copy to---> [sugarcrm_root_dir]\ htdocs\sugarcrm\modules\Connectors\connectors\sour ces\ext\soap\strikeiron\language
In other hand, you can deploy this connector by building the zip package file and upload it to SugarCRM using the instruction at http://www.sugarcrm.com/crm/index.ph...05.2.1.34.html
Step 5 – Setup the StrikeIron Cortera Link.
This link is an asp.net page. It consumes the StrikeIron Cortera service to return result for the CloudView.
In order to do that, you need to create a asp.net page, add the following web reference into: http://wslite.strikeiron.com/Cortera...Lite.asmx?WSDL.
Then modify Page_Load event:
Then build the solution and host this web page to a server, such as: http://a.server.com/sisugar.aspxPHP Code:...
public partial class Sugar_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request["Company"] != null)
{
string company = Request["Company"].ToString();
com.strikeiron.wslite.CorteraLite service = new com.strikeiron.wslite.CorteraLite();
com.strikeiron.wslite.CompanySearch objComp = new com.strikeiron.wslite.CompanySearch();
objComp.CompanyName = company;
CorteraOutput output = service.SearchByCompany(objComp);
CorteraData[] arrData = output.ServiceResult.Companies;
string result = "";
result += "Remaining hits: " + output.RemainingHits + "</br>";
if (arrData != null && arrData.Length > 0)
{
result = "Company Name: " + arrData[0].CompanyName + "</br>";
result += "Address: " + arrData[0].Address + "</br>";
result += "City: " + arrData[0].City + "</br>";
result += "Postal Code: " + arrData[0].PostalCode + "</br>";
result += "State: " + arrData[0].State + "</br>";
}
else
{
result += "No company found";
}
Response.Write(result);
}
}
}
Step 6 – Test the final result
Login to SugarCRM under the role in which you can change the application configuration. Open Admin>Connector Settings
Choose Set Connector Properties.
Enter your link of the hosted asp.net page into “StrikeIron Cortera Link”, then click Save.
Now move to Accounts page, you will see a list of Account, click on one you want to verify the company location. You will see the Account Detail and a small StrikeIron icon. Hove over it, you will get below result:
Variations: you can change the asp.net page so that it will return a list of search instead of one row like above. Another variation of this sample is that instead of using <iframe> in tpls\default.tpl file to call the StrikeIron Cortera Link, you can call StrikeIron Cortera Lite directly without using StrikeIron Cortera Link from this default.tpl file using some Ajax SOAP call like a html page calls SOAP Web services.
-Have fun.
Dan Tong
References:
1. Connector Framework User Guide: http://www.sugarcrm.com/crm/index.ph...05.2.1.34.html
2. StrikeIron Lite Web services: http://www.strikeiron.com/marketplace/liteservices.aspx


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks