Pages

Tuesday, October 23, 2012

SugarCRM: Imports Revisited

A few days ago I found myself in a conversation touching on a subject that made me realize there was a need to expand on a related post of mine from some time back.

The topic at hand related to importing data, which, as I discuss in that prior post, avoiding problems requires that some attention be given to the source data. Continuing this discussion, there are additional points worth mentioning about different data types.

More specifically, below are some parameters to keep in mind as you prepare your data for import:


Recipient SugarCRM Field Data Type
Source Data Format

DateTime

2012-10-23 09:30:00

Date

2012-10-23

MultiSelect

^Value^
^Value1^,^Value2^,^Value3^

Value must match the Item Name entry defined in the associated drop down list, including case.


DropDown

Value must match the Item Name entry defined in the associated drop down list, including case.


Checkbox

1 = Checked, 0 = Unchecked


Radio

1 = Selected, 0 = Unselected


I hope that helps save you some time at import time!

Wednesday, October 17, 2012

SugarCRM: Lets Go Fishing

Those of you that read my previous article describing the process for dynamically hiding subpanels may have been left wondering something about the instructions. Reading the article we find that the specific bit of code that hides the subpanel reads as follows:

unset($layout_defs['Accounts']['subpanel_setup']['opportunities']);

In the above, the subpanel for Opportunities data on the Accounts module is being suppressed. But how does one come about knowing the name of the array to manipulate? Further to this, where did the value of 'opportunities' come from? What are the rules for the other panels?

Fortunately, the answers to those questions are all found in one file: subpaneldefs.php

This file can be found in <sugar_root>/modules/<module>/metadata. For our referenced example, suppressing the Opportunities subpanel on Accounts records, the corresponding subpaneldefs.php file that contains our answers is located in <sugar_root>/modules/Accounts/metadata.

Said file will contain a listing of all the defined subpanels for the Accounts module, along with various parameters that are used to display them. To manipulate the elements, create a layoutdefs.ext.php file, as with suppressing the subpanel, focusing on the specific elements of the array that you wish to change.

Don't forget to run a Quick Rebuild and Repair to apply any changes you wish to introduce via layoutdefs.ext.php.

Thursday, September 20, 2012

VB.NET Code Snippet: Pardot Login

Sometimes it is hard to appreciate the degree to which the development world has changed over the last ten years or so, especially when one is surrounded by it on a daily basis.

Anyway, I was recently reminded of it while working on a project involving Pardot, the popular online marketing service provider. In past years, finding .NET based code snippets -- or examples -- demonstrating the process of interacting with the application programming interface (API) for such a service would have been relatively easy. The development world, however, has long moved past that and .NET is no longer considered the dominant player it once was. As a result, snippets of the type I referenced earlier have tended to become a bit more scarce.

But there are still a number of .NET users like myself out there, and here is a code snippet I wanted to share which I think others might find helpful. This VB.NET snippet demonstrates the manner in which we can login to the Pardot API. 

Dim sResults As String

'Email address used to login to Pardot         
Dim sPardotEmail As String = "my_email@mymail.com"
'Corresponding password for login 
Dim sPardotPwd As String = "my_pardot_password" 
        
'Obtained from user settings page in Pardot -- user specific
Dim sPardotUserKey As String = "pardot user key" 

Dim sURL As String = "https://pi.pardot.com/api/login/version/3"
Dim sMsg As String = "email=" & sPardotEmail & "&password=" & sPardotPwd & "&user_key=" & sPardotUserKey
Dim wrRequest As System.Net.WebRequest = System.Net.WebRequest.Create(sURL)

Dim byteArray As Byte() = Encoding.UTF8.GetBytes(sMsg)

wrRequest.Method = "POST"
wrRequest.ContentType = "application/x-www-form-urlencoded"
wrRequest.ContentLength = byteArray.Length

'Post it to Pardot!
Dim dataStream As System.IO.Stream = wrRequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()

'Get the response from Pardot
Dim wrResponse As System.Net.WebResponse = wrRequest.GetResponse()
dataStream = wrResponse.GetResponseStream()
Dim dataReader As New System.IO.StreamReader(dataStream)

'Response is an XML document containing the Pardot API key
sResults = dataReader.ReadToEnd() 

dataReader.Close()
dataStream.Close()
wrResponse.Close()

Your first step when integrating with Pardot should always be to login, as that process provides the Pardot API key that in turn is used in subsequent API calls.

If you have some useful tips for Pardot API integration and .NET, please share in the comments. Thanks in advance.