Title: MS CRM Customization - How to Qualify Leads in CRM - Set Lead State and Status in CRM Author: Greg Dubinovskiy Email: [email protected] Environment: Microsoft CRM, SQL Server, SQL Keywords: Microsoft CRM, MS CRM Customization, MS CRM Leads, How to Qualify Leads in CRM, Set Lead State and Status in CRM, MS CRM Customization Tools, ASP.NET, VB.NET Level: Intermediate Description: Build Process to Qualify Leads Section Miscellaneous SubSection General
The article presented bellow, shows how to setup a process to allow
qualify Leads in Microsoft CRM.
In MS CRM, there is a "Convert Lead" process, that allows to Convert a Lead to Account/Contact/Opportunity:
So, it will Create an Account, or Contact, or Opportunity and set Lead status to Qualified
Purposes of this article is to show how to setup a process/flow to only qualify a Lead without creating a Account/Contact/Opportunity record:
Customizing CRM is not hard at all, thanks to semi-open web interface and SQL Server database. This article shows how to develop your own CRM Customization Tool for your business solutions.
Quickly customize Microsoft CRM - CRM Leads - so that you capture and manage the exact data you need to increase sales and service effectiveness.
Customize the Microsoft CRM user interface - Learn how to customize the Microsoft CRM user interface by creating and modifying forms, views, and previews.
Microsoft CRM allows system integrators to create a highly customized and integrated application. In addition, the solution supports flexible options that enable users to focus only on the features they need to perform the tasks their jobs require.
(see other Siccolo articles about working with Microsoft CRM:
MS CRM Customization - Import Leads from Excel via Email - Create MS CRM Leads Automatically
and
MS CRM Customization - How to add custom CRM Report to Reports Grid in CRM
)
LoadLeadInfo()
QualifyLead()
Imports System.Data Imports System.Data.SqlClient Public Class LeadInfo Public Lead_Subject As String Public Lead_State As String Public Lead_Status As String Public Lead_StateCode As Integer Public Lead_StatusCode As Integer Public Function LoadLeadInfo(ByVal LeadID As String, _ ByRef ErrorInfo As String) As Boolean Try Dim strConnectInfo As String = - [your connect string to SQL Server hosting MS CRM database] - Dim objConnection As SqlConnection = New SqlConnection(strConnectInfo) Dim strSQL As String strSQL = "exec dbo.p_Lead_LeadInfo " & "'" & LeadID & "'" Dim objCommand As SqlCommand = New SqlCommand(strSQL, objConnection) objConnection.Open() Dim objData As SqlClient.SqlDataReader objData = objCommand.ExecuteReader(System.Data.CommandBehavior.SingleRow Or System.Data.CommandBehavior.CloseConnection) With objData .Read() ' read Lead information, such as Lead topic: Lead_Subject = .GetString(.GetOrdinal("Subject")) ' we also need Lead State and Lead status:! Lead_State = .GetString(.GetOrdinal("StateCodeString")) Lead_Status = .GetString(.GetOrdinal("StatusCodeString")) Lead_StateCode = .GetInt32(.GetOrdinal("StateCode")) Lead_StatusCode = .GetInt32(.GetOrdinal("StatusCode")) .Close() End With objConnection.Close() Return True Catch e As Exception ErrorInfo = e.ToString Return False End Try End Function
create procedure p_Lead_LeadInfo ( @lead_id varchar(255) ) as set nocount on select isnull( upper(Subject) , '') as Subject , StateCode , StatusCode , (select value from dbo.StringMap where ObjectTypeCode = 4 -- Leads and AttributeName = 'StateCode' and AttributeValue = l.StateCode) as StateCodeString , (select value from dbo.StringMap where ObjectTypeCode = 4 -- Leads and AttributeName = 'StatusCode' and AttributeValue = l.StatusCode) as StatusCodeString from dbo.Lead l where LeadID = @lead_id set nocount off
QualifyLead()
function:
Public Function QualifyLead(ByVal LeadID As String, _ ByRef ErrorInfo As String) As Boolean Try Dim strConnectInfo As String = - [your connect string to SQL Server hosting MS CRM database] - Dim objConnection As SqlConnection = New SqlConnection(strConnectInfo) Dim strSQL As String strSQL = "exec dbo.p_Lead_QualifyLead " & "'" & LeadID & "'" Dim objCommand As SqlCommand = New SqlCommand(strSQL, objConnection) objConnection.Open() Dim Rows As Integer = objCommand.ExecuteNonQuery() objConnection.Close() Return True Catch e As Exception ErrorInfo = e.ToString Return False End Try End Functionwhere SQL stored procedure to change Lead status in MS CRM database:
create procedure p_Lead_QualifyLead ( @lead_id varchar(255) ) as set nocount on update dbo.Lead set StateCode = 1 , StatusCode = 3 where LeadID = @lead_id set nocount off
update LeadBase set StateCode =0 , StatusCode = 1 where LeadID = - [Lead ID value] -
qualify_lead.aspx
code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Try
Dim LeadID As String
'load data here
If Not IsPostBack() Then
LeadID = Request("oId")
If LeadID = "" Then
Me.lblLeadName.Text = "Lead: Unknown"
ShowError("Lead ID is missing!")
Else
Dim ErrorInfo As String
If Not LoadLeadInfo(LeadID, ErrorInfo) Then
ShowError(ErrorInfo)
End If
End If
End If
' Page.DataBind()
Catch ex_load_page As Exception
ShowError("Failed to load page:" & ex_load_page.ToString())
End Try
End Sub
LoadLeadInfo()
function:
Private Function LoadLeadInfo(ByVal LeadID As String, ByRef ErrorInfo As String) As Boolean
Try
Dim objLeadInfo As New LeadInfo()
If Not objLeadInfo.LoadLeadInfo(LeadID, ErrorInfo) Then
Throw New System.Exception("Failed to retrieve Lead info! Error:[" & ErrorInfo & "]")
End If
With objLeadInfo
Me.lblLeadName.Text = "Lead: " & " [" & LeadID & "]"
Me.lblUserID.Text = Request.ServerVariables("LOGON_USER")
Me.lblLeadStatus.Text = "Lead: " & " - Status: " & .Lead_Status & "/" & .Lead_State & ""
If .Lead_StateCode = 1 Or .Lead_StatusCode = 3 Then
'already qualified!
Me.lblLeadStatus.Text = Me.lblLeadStatus.Text & "- Already Qualified!" & ""
'do not allow to Qualify already qualified Lead!
Me.cmdQualify.Enabled = False
Else
'ok
End If
End With
Return True
Catch e As Exception
lblErrorInfo.Text = e.ToString
lblLeadName.Text = e.Message
lblErrorInfo.Visible = True
Return False
End Try
End Function
Private Sub cmdQualify_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cmdQualify.Click
Dim ErrorInfo As String
If Not QualifyLead(ErrorInfo) Then
ShowError("Failed to Qualify Lead! - " & ErrorInfo)
End If
End Sub
Private Function QualifyLead(ByRef ErrorInfo As String) As Boolean
Dim Result As Boolean
Try
Dim LeadID As String = Request("oId")
If LeadID = "" Then
Throw New System.Exception("Lead ID is missing!")
End If
Dim objLeadInfo As New LeadInfo()
If Not objLeadInfo.QualifyLead(LeadID, ErrorInfo) Then
'show error!
Throw New System.Exception("Failed to Qualify Lead! Error:[" & ErrorInfo & "]")
Else
'refresh screen!
LoadLeadInfo(LeadID, ErrorInfo)
End If
Return True
Catch e As Exception
lblErrorInfo.Text = e.ToString
lblLeadName.Text = e.Message
lblErrorInfo.Visible = True
Return False
End Try
End Function
Qualify
.
Now, we just need to add a button to menu on Lead Screen:
isv.config
file, under [MS CRM web server]\inetpub\wwwroot\_Resources
:
[installation drive and folder]\wwwroot\_Resources\isv.config
ISVIntegration
setting in the web.config file to On. Web.config
is located at:
[installation drive and folder]\wwwroot\web.config
The ISVIntegration setting is used as a performance optimization. When there are no customizations to be rendered, the value for this setting should be Off.
isv.config
.
Example
<ToolBar ValidForCreate="0" ValidForUpdate="1"> <Button Title="Test" ToolTip="Info on Test" Icon="/_imgs/ico_18_debug.gif" Url="http://www.microsoft.com" PassParams="1" WinParams="" WinMode="0"/> <ToolBarSpacer/> <Button Title="Test" ToolTip="Info on Test" Icon="/_imgs/ico_18_debug.gif" Url="http://www.microsoft.com" PassParams="1" WinParams="" WinMode="1"/> </ToolBar>
no improvements so far. nearly perfect.