web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

franchise upload application

(0) ShareShare
ReportReport
Posted on by 105

hi everebody I have written this code to upload the franchise in CRM. But it is not updating in crm as well as database. Can anybody tell me where is the prob in this code.

Imports CustomersUpload.CRMReferences

Imports CustomersUpload.MetaDataReference

Imports System.IO

Public Class UpdateCustomer

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents btnupdate As System.Web.UI.WebControls.Button

Protected WithEvents txtFilePath As System.Web.UI.HtmlControls.HtmlInputFile

Protected WithEvents lblLogDetails As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

#Region " Global Variables Declaration "

Dim strErrDataCustLine, strFilename As String

Dim TempContactGUID As New Guid

Dim strReaderLine, strErrorMsg, strParentCustomerType As String

Dim ArrContactDetails(), ArrDSADetails(), ArrFranchiseDetails() As String

Dim intCount As Integer, intContactFind As Integer = 0

#End Region

 

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

btnupdate.Attributes.Add("onclick", "return NavigatePage();")

End Sub

Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click

Try

Dim strFileName As String = txtFilePath.PostedFile.FileNameDim c As String = System.IO.Path.GetFileName(strFileName)

txtFilePath.PostedFile.SaveAs("D:\UploadedRecords\" + c)

Dim processingCount As Integer = 0

Dim objStreamReader As StreamReaderobjStreamReader = New StreamReader("D:\UploadedRecords\" + c)

 

Dim objService As New CrmService

objService.Url = "http://10.65.1.50/mscrmservices/2006/crmservice.asmx"

objService.Credentials = New System.Net.NetworkCredential("administrator", "@rtrade1", "RtradeCRM")

Try

strReaderLine = objStreamReader.ReadLine()

While Not strReaderLine Is Nothing

Try

strReaderLine = strReaderLine.Replace("""", "")

ArrContactDetails = strReaderLine.Split("|")

If Not IsDBNull(ArrContactDetails(0)) AndAlso ArrContactDetails(0).ToString.Trim <> String.Empty Then

Dim ClientContact As New contact

Dim cols As New AllColumns

Dim condition1 As New ConditionExpression

condition1.AttributeName = "employeeid"

condition1.Operator = ConditionOperator.Equal

condition1.Values =
New String() {ArrContactDetails(0)}Dim filter As New FilterExpression

filter.FilterOperator = LogicalOperator.And

filter.Conditions = New ConditionExpression() {condition1}

Dim query As New QueryExpression

query.EntityName = EntityName.contact.ToString()

query.ColumnSet = cols

query.Criteria = filter

Dim contactdetails As BusinessEntityCollection = objService.RetrieveMultiple(query)

'objService.Dispose()

Dim objContact As New contact

If contactdetails.BusinessEntities.Length > 0 Then

objContact = CType(contactdetails.BusinessEntities(0), contact)

objContact.new_franchisecode = ArrContactDetails(1)

Dim branchid As String = getbranchid(ArrContactDetails(2))

If Not IsNothing(branchid) Then

objContact.new_branchid = New Lookup

objContact.new_branchid.Value = New Guid(branchid)

End If

objService.Update(objContact)

End If

Else

lblLogDetails.Text = "Mandatory Values missing in this record"

End If

strReaderLine = objStreamReader.ReadLine()

Catch ex As System.Exception

strErrorMsg = "ErrorMessage: " + ex.Message + " Source: " + Err.Source

lblLogDetails.Text = lblLogDetails.Text + "<p>" + strErrorMsg

strReaderLine = objStreamReader.ReadLine()

End Try

processingCount = processingCount + 1

lblLogDetails.Text = lblLogDetails.Text + "<p>" + processingCount.ToString & " Customer Records Processed"

End While

Catch ex As System.Exception

strErrorMsg = "ErrorMessage: " + ex.Message + " Source: " + Err.Source

lblLogDetails.Text = strErrorMsg

End Try

objStreamReader.Close()

Catch ex As Exception

lblLogDetails.Text = ex.Message

End Try

End Sub

#Region " Get Existing Branch Details "

Private Function getbranchid(ByVal branchid As String) As String

Try

Dim objService As New CrmService

objService.Url = "http://10.65.1.50/mscrmservices/2006/crmservice.asmx"

objService.Credentials =
New System.Net.NetworkCredential("administrator", "@rtrade1", "RtradeCRM")

Dim id As String

Dim fullBranchId As String

fullBranchId = "BR" + branchid

Dim cols As New ColumnSet

cols.Attributes = New String() {"new_branchid"}

Dim condition As New ConditionExpression

condition.AttributeName = "new_branchcode"

condition.Operator = ConditionOperator.Equal

condition.Values =
New String() {fullBranchId}Dim filter As New FilterExpression

filter.FilterOperator = LogicalOperator.And

filter.Conditions = New ConditionExpression() {condition}

Dim query As New QueryExpression

query.EntityName = EntityName.new_branch.ToString()

query.ColumnSet = cols

query.Criteria = filter

Dim newbranch As BusinessEntityCollection = objService.RetrieveMultiple(query)

If newbranch.BusinessEntities.Length > 0 Then

Return (CType(newbranch.BusinessEntities(0), new_branch).new_branchid.Value.ToString)

End If

Return Nothing

Catch ex As Exception

lblLogDetails.Text = ex.Message

End Try

End Function

#End Region

End Class

 

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Baris KANLICA Profile Picture
    User Group Leader on at

    Is it give an error?

  • Arif Zaidi Profile Picture
    45 on at

    I am looking to implement Microsoft CRM I wanted to see if there is anyother Franchise organization using Microsoft CRM. Our sales department wants to make sure that it works in Franchise sale environment. If someone can help me find CRM users that are franchise organization I will greatly appriciate that.

    Arif

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans