Open main menu

Changes

4,225 bytes added ,  10:41, 7 February 2017
m
{{Not free|CiviCRM}}
 
[http://en.wikipedia.org/wiki/Sugarcrm SugarCRM] is the world's leading Customer Relationship Management (CRM) software available with complete freedom under the GPL license. For companies that want more than freedom, SugarCRM Inc, fully backs the product with expert support, service, training and customization. SugarCRM offers several deployment options, including on-demand, on-premise and appliance-based solutions to suit customers' security, integration and configuration needs. Because CRM software captures the varied relationships between a company and it's sources of revenue, most businesses really stand to benefit from the intelligence provided by a CRM system. All companies already have 'ad-hoc' methods to track leads, contacts, customer accounts and the company interactions with these (e.g. spreadsheets, lists and email records). They may even have organized CRM solutions in place. Either way, once you decide to adopt an open and standards-based solution like SugarCRM, your first order of business will be to load it with your existing data. SugarCRM has importing (and exporting) utilities that make it easy to do this, so these wizards will not be the focus of this article. Instead, we'll focus on programmatic interaction with the system.
<!--
{{Infobox Company
|company_name=SugarCRM
|company_type=Private
|foundation=[[California]] 2004
|location=[[Cupertino, California]]
|industry=CRM Software
|products= Sugar Community Edition, Sugar Professional, Sugar Enterprise
|num_employees=150+
|parent=
|subsid=
|homepage=[http://www.sugarcrm.com/ www.sugarcrm.com]
}} -->
{{Infobox
|name = SugarCRM
|bodystyle =
|title = Company Info
|titlestyle =
|above =
|abovestyle =
|image =
|imagestyle =
|caption =
|captionstyle =
|headerstyle =
|labelstyle =
|datastyle =
 
|header1 =
|label1 = Company Name
|data1 = SugarCRM
|header2 =
|label2 = Company Type
|data2 = private
|header3 =
|label3 = Founded
|data3 = California 2004
|header4 =
|label4 = Industry
|data4 = CRM Software
|header5 =
|label5 = Products
|data5 = Sugar Community Edition, Sugar Professional, Sugar Enterprise
|header6 =
|label6 = Employees
|data6 = 150+
|header7 =
|label7 = Website
|data7 = [http://www.sugarcrm.com/ www.sugarcrm.com]
|header8 =
|label8 =
|data8 =
|header9 =
|label9 =
|data9 =
|header10 =
|label10 =
|data10 =
}}
== Introduction ==
Typically a company will deploy the CRM system and will also create one or more pipelines which act as conduits to capture new account, and contact information. This article will show how to establish a web service, using [http://en.wikipedia.org/wiki/SOAP SOAP] to add contacts and accounts to your [[Installing SugarCRM|SugarCRM installation]]. As an example scenario, let's suppose that a conference organizer wants to offer a sign-up sheet on their existing website. The existing website could be a [http://drupal.org Drupal] content management system (CMS) which not only manages the conference, but also adds company and individual contact details to the SugarCRM system via the web service. The details on creating the form for the capture are beyond the scope of this article but the capture routines could easily handle a form input (HTTP POST) just as easily as we read input from a file . Again our focus for today will be on the plumbing of the interaction with the SOAP server.
 
== Goal ==
Import records into SugarCRM without using existing functionality, import wizards but rather by writing some a tool in [http://en.wikipedia.org/wiki/PHP PHP tool ] to do the work. Records should go into Accounts and Contacts, which obviously implies while creating a relationshipbetween the two.
== Resources Used Requirements ==* http://wwwAssume that we start with a spreadsheet that has column headings matching the 17 fields shown below.sugarcrm Assume too that we want to capture all of the data in the sample.com/wiki/index (The owner of the data collected it for a reason and they wouldn't be too happy with a loss of data in a migration to a new application!) I did not define new fields in the database, but I did correlate my data source to the Accounts and Contacts tables.php?title=SOAP_Intro_and_Practical_Examples* http://freephile Because I had parsed the data source (spreadsheet or CSV file) for column headings, I simply exported that variable and then used it as a comment right in my code workup as I went.com/crm/index.php?module=Home&action=TrainingPortal* http://freephile.com/crm/soap.php* What I mean is that I created a PHP (array) variable of the 17 field names, and then used the [http://www.sugarcrm.com/wiki/index.php?title=SOAP_in_PHP* http://dietrich.ganx4.comnet/nusoapvar_export|var_export]() function to print it and copy/* http://www.beanizer.org/site/index.php/en/Articles/Sugar-CRM-integration-with-custom-PHP-applications-paste into a comment block so that Icould mark up a plan for mapping those fields into fields in SugarCRM.html
<source lang== Download "php">print '<pre>'; var_export ($arrFields); print '</pre>';// copy and Install SugarCRM paste that output; then add comments about which fields go into which table// comment the whole block so that it remains as a reference in the toolarray ( 0 => 'Company Name',// a:name 1 => 'Industry', // a:industry # I went to the [http 2 => 'First Name', // c:first_name 3 => 'Last Name', //sugarcrm.com SugarCRM homepage] c:last_name 4 => 'Fax', and clicked the top navbar link to "Sugar Open Source" // a:phone_fax c:phone_fax# I skipped the "Wizard" and went right to the "Download Page" because I know what I 5 => 'Address'm doing and also have , // a pre-existing setup of Linux:billing_address_street c:primary_address_street 6 => 'City', Apache MySQL and PHP - so I only want the application // a:billing_address_city c:primary_address_city# I downloaded SugarCE-5.0.0e.zip (production release) 7 => 'State', // a:billing_address_state c:primary_address_state# I visited the recommended "Installation" instructions page at http 8 => 'Zip Code', // a:billing_address_postalcode c:primary_address_postalcode 9 => 'Country', //www.sugarforge.orga:billing_address_country c:primary_address_country 10 => 'Notes', //contenta:description 11 => 'Work Phone', /installation/a:phone_office c:phone_work# Then I installed it according to the instructions 12 => 'Other Phone', however I immediately ran into trouble because the instructions did say to chmod 766 all files that needed to be writable by the web_user. // a:phone_alternate c:phone_other# This command renders the directories non-executable which manifests in include errors because the web user (www-data) can not see into those directories (to find includes). The following snippet is 13 => 'Email', // a fix:email c:email1<source lang 14 ="bash">'website', // a:website # find directories in the . 15 => 'employees', //crm path and change the mode on them so that all users can execute (see into) the directory a:employees find . 16 => 'ticker_symbol'/crm/ -type d |xargs chmod a+x :ticker_symbol )</source> resolved the include errors
=== Using a Form ===The instructions also fail to mention that the application wants to create a [http://www.htaccess file (which doesn't exist in the distribution and would not necessarily be writable to the web usersugarcrm. As a failsafe, the information is printed to the screen in the installercom/wiki/index. However it doesn't properly display (lacking newline characters) so the content is not suitable for copy php?title=SOAP_Intro_and_Practical_Examples SOAP Intro and paste into the file. I resorted to the source which generates the .htaccess contentPractical Examples], and used that. An alternative is to simply touch and chmod 777 shows a .htaccess file '''prior''' to running the installer; and then chmod'ing it go=r after installsimple form-based processing script for leads.
== Ideas on How to do the import ==My self-imposed requirement was to capture all of the data provided -- assuming the owner of the data collected it for a reason and that they wouldn't The form can be too happy with a loss of data found in a migration to a new application. I looked briefly at the import functionality exposed by the application, but noticed how the lead capture did not reflect the same data profile as "examples" directory in the source that I had. === Existing Work ===My first instinct is always to find info about somebody doing this before (e.g. APIs, Documentation, forum questions, Wikis) I searched the wiki for importing or APIs and quickly found the SOAP Intro and Practical Examples, so I figured I was onto a fast track.However, Note: the soap example worked with a frontend form (which wasn't explained much) leading me to investigate more into what was required by the soap service. When I found the form in "examples", it did not work as an application entry point (because even though it defined ('sugarEntry', true); there was also an IF that pre-empted that definition) -- because other code was being loaded before requests inside the SugarCRM install directory will automatically bootstrap the formSugarCRM system). I did not immediately see To work around this cause for the example failure, so I either put the example form outside the application directory and successfully used or define sugarEntry as true ''without'' the 'if' conditional. Using the lead capture form to insert a single lead This is illustrated at http://www.sugarcrm.com/wiki/index.php?title=Creating_a_lead_capture_form_for_your_websiteSeeing that the example workedIf your needs are more complex, but did not capture all the details provided in the data exercise, I knew I should look you can learn more by looking at the existing functionality of modules dealing with Import (dataMaps), the database abstraction layer (SugarBeans and VarDefs) or the database directly to get a clearer picture of what I needed to label everythinggoing on in the SugarCRM system.
=== Use the Source Luke ===
My second instinct was to look at the source. Answers are always found in the source, with the caveat that it can be confusing and/or time-consuming to find those answers.
Looking at the full application import routines and the four-step forms for importing leads, it was obvious that there was is a lot of example machinery that I didn't necessarily need or want you could use to get involved with to simply import recordscreate a sophisticated web front-end using SugarCRM internals. For instancethis exercise, I would not want to (re-)write the form assume that we'll be operating between two websites, and UI handling when so I will simply needed to insert records into a the database. This made me reconsider using the communicating with SugarCRM's SOAP example to do the job. In essence, it would only need to read the exercise data and create full records for the 50 provided leads. <!--From looking at the source code of the import routines, I noticed that the modules/Import/config.php file defined various types of data profiles, and that the "Salesforce" profile was close to the data that I hadserver.
; Tip: You can peer into the SugarCRM environment with a call to PHP's 'get_defined_vars()'. This will give you some information about field maps etc.
<source lang="php">
# temp.php to show a concise view of the variables defined in the config script
)
</source>
-->
== Using SOAP ==
Note: Soap SOAP examples seem to have changed can obviously change slightly over time with the addition of a version numberSugarCRM, so you must be careful about what example you use, and generally rely on the source to be the definitive source ;-)
* soap/SoapPortalUsers.php
* soap/SoapSugarUsers.php
===Accounts fields: ===
See [[Importing_contacts/Accounts|See the SOAP profile for Accounts]]
=== Contacts fields: ===
See [[Importing_contacts/Contacts|See the SOAP profile for Contacts]]
$arrData[$k] = explode($separator, $v);
}
// insert our Account records
foreach ($arrData as $record) {
// Accounts
$set_entry_params = array(
'session' => $session_id,
)
);
// make the soap call
$result = $soapclient->call('set_entry',$set_entry_params);
} // print "\n <br />Entry results:<br />\n<pre>\n"; var_export ($result); print "\n</pre>\n"; // insert Contactsthe return value will give us the unique identifier for the Account record, which we // then use to create a relationship entry when creating the Contactforeach ( $arrData as accountId = $record) {result['id'];  // Contacts
$set_entry_params = array(
'session' => $session_id,
array('name'=>'email', 'value'=>$record[$fieldKeys['Email']]),
array('name'=>'account_name', 'value'=>$record[$fieldKeys['Company Name']]), // relation
array('name'=>'account_id', 'value'=>$accountId), // relation
array('name'=>'assigned_user_id', 'value'=>$user_guid)
)
);
// make the soap call to create the (related) Contact entry
$result = $soapclient->call('set_entry',$set_entry_params);
print "\n <br />Contact Entry results:<br />\n<pre>\n"; var_export ($result); print "\n</pre>\n";
$contactId = $result['id'];
/**
// alternately, if you have both ids, you can use set_relationship
$set_relationship_params = array(
'session' => $session_id,
'set_relationship_value' => array(
'module1' => 'Contacts',
'module1_id' => $contactId,
'module2' => 'Accounts',
'module2_id' => $accountId
)
);
$result = $soapclient->call('set_entryset_relationship',$set_entry_paramsset_relationship_params); print "\n <br />Relationship results:<br />\n<pre>\n"; var_export ($result); print "\n</pre>\n";  */
}
</source>
I didn== Conclusion ==In this article we't just arrive at ve shown how the SugarCRM system is enterprise-ready in that it has a fully built SOAP service that can be used to integrate the code magicallysystem with one or more 'front-end' websites or applications for data capture. InsteadWith important information easily added to the system, I just it allows the company to focus resources on managing the most valuable assets. Due to SugarCRM'drews open source nature and standards support, it' s easy to extend and integrate the system with other existing or new infrastructure components. In future articles, we'll take a map of the columns of source data that I hadlook at still more interesting integrations with SugarCRM such as collaboration, document management and marked where each data element would potentially fit into the target database tableknowledge management.
<source lang="php">
print '<pre>'; var_export ($arrFields); print '</pre>';
array (
0 => 'Company Name',// a:name
1 => 'Industry', // a:industry
2 => 'First Name', // c:first_name
3 => 'Last Name', // c:last_name
4 => 'Fax', // a:phone_fax c:phone_fax
5 => 'Address', // a:billing_address_street c:primary_address_street
6 => 'City', // a:billing_address_city c:primary_address_city
7 => 'State', // a:billing_address_state c:primary_address_state
8 => 'Zip Code', // a:billing_address_postalcode c:primary_address_postalcode
9 => 'Country', // a:billing_address_country c:primary_address_country
10 => 'Notes', // a:description
11 => 'Work Phone', // a:phone_office c:phone_work
12 => 'Other Phone',// a:phone_alternate c:phone_other
13 => 'Email', // a:email c:email1
14 => 'website', // a:website
15 => 'employees', // a:employees
16 => 'ticker_symbol// a:ticker_symbol
',
)
</source>
And there are a few extra elements like GUID that go into <table class="toc"><tr><td>-- Greg Rundlett<br />Greg Rundlett is an open source technologist. He currently manages the actual scripTechnology Services team at [http://www.oasis-open.org OASIS]. <br />''This website is not affiliated nor endorsed by any third-party .''</td></tr></table>
The first attempt did not establish the record relationships the way that I intended by using the '''Company Name''' as the relation. It seemed plausible from the definition, but it didn't happen that way.
== Postscript: Some Issues discovered Improvements for SugarCRM == As with any software, there is always room for improvement. Here are some minor issues that I noted in the course of writing this article.
# "Import Step 2: Upload Export File" is a confusing title on the second step of the "Import Contacts" wizard. How can one use the words 'import', 'upload', 'export' all at once? It could read "Import Step 2: Select Data File to load"
# Typographical bug: I saw that the term "custom_delimeted" in the language files. It doesn't actually cause any errors, but b/c the term is used elsewhere (spelled correctly), this typo could potentially lead to a real bug down the line.
## ./modules/Import/ImportStep1.html
## ./modules/Import/ImportStep2.php
# The source is formatted poorly, or practically not at all in some cases, due to various editors using different space and tab settings, and line endings. PHPBeautifier [http://pear.php.net/package/PHP_Beautifier PHP Beautifier] used in a commit hook would solve this in the repoversion control system. Coding standards and configuration files like vim modelines would solve this on the developer desktop. Being open source, I can pass this information on to the developers (or even get involved myself by posting articles like this to [http://www.sugarcrm.com/wiki/index.php?title=Main_Page the wiki]) and will likely see a positive response to these suggested fixes. Note too - SugarCRM fosters an extended community of value-add partners through it's [http://www.sugarforge.org/ forge site]. == Further Resources ==* http://www.sugarcrm.com/wiki/index.php?title=SOAP_Intro_and_Practical_Examples* http://freephile.com/crm/index.php?module=Home&action=TrainingPortal* http://freephile.com/crm/soap.php* http://www.sugarcrm.com/wiki/index.php?title=SOAP_in_PHP* http://dietrich.ganx4.com/nusoap/* http://www.beanizer.org/site/index.php/en/Articles/Sugar-CRM-integration-with-custom-PHP-applications-I.html [[Category:CRM]][[Category:Code]][[Category:Software]]
4,558

edits