Exemplo n.º 1
0
        private int pushContactsToCRM()
        {
            login(); // performs web service (SOAP) login to Sage CRM

            ArrayList hubSpotGuids = new ArrayList();
            mapLead = getMap("Lead");

            DataSet ds = getLeadsToProcess(); // select * from HubSpotLeadStaging where Processed_Timestamp is null
            ULogging.writeToDebugLog(AppGlobal.getAppLogger(), "Number of Contacts in SELECT: " + ds.Tables[0].Rows.Count);

            for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                HubSpotLead aContactRecord = new HubSpotLead(ds.Tables[0].Rows[i]["JSON_Data"].ToString());
                string hubSpotLeadGuid = aContactRecord.ContactIdentity_Profiles[0].current_Lead_Guid;
                string hubSpotVid = aContactRecord.ContactDetailRecord.getStringValue("vid");
                // KVW added 05132013
                string hubSpotEmail = aContactRecord.ContactIdentity_Profiles[0].Email;
                // KVW added 05132013
                strPublicLink = aContactRecord.ContactDetailRecord.getStringValue("profile-url");
                DateTime dInsertDate = getDateTimeValue(aContactRecord.ContactHeaderRecord.getStringValue("addedAt"));
                dInsertDate = dInsertDate.AddMilliseconds(- dInsertDate.Millisecond);

                ds.Tables[0].Rows[i]["Processed_Timestamp"] = SLX_Data.getNewTimestamp();

                string sqlQuery = "lead_deleted is null and lead_hubspotvid = '" + hubSpotVid + "'";
                queryresult entityResult = binding.query(sqlQuery, "Lead");
                ewarebase[] leadBase = entityResult.records;
                if (leadBase == null && !string.IsNullOrEmpty(hubSpotLeadGuid))
                {
                    sqlQuery = "lead_deleted is null and lead_hubspotguid = '" + hubSpotLeadGuid + "'";
                    entityResult = binding.query(sqlQuery, "Lead");
                    leadBase = entityResult.records;
                }

                // KVW added 05132013
                if (leadBase == null && !string.IsNullOrEmpty(hubSpotLeadGuid))
                {
                    sqlQuery = "lead_deleted is null and lead_personemail = '" + hubSpotEmail + "'";
                    entityResult = binding.query(sqlQuery, "Lead");
                    leadBase = entityResult.records;
                }
                // KVW added 05132013

                this.dtRecentUpdate = DateTime.MinValue;
                if (leadBase != null)
                {
                    lead CRMLead = (lead)leadBase[0];
                    this.dtRecentUpdate = CRMLead.hubspotrecentupdate;
                }

                if (dInsertDate > dtRecentUpdate)
                {
                    strFormName = "";
                    strConversionEvents = "";
                    strFirst_Conversion_Date = "";
                    strLast_Conversion_Date = "0";

                    if (aContactRecord.ContactForm_Submissions.Count > 0)
                    {
                        strConversionEvents = aContactRecord.ContactForm_Submissions.Count.ToString();
                        foreach (HubSpotContactForm_Submission ContactForm_Submission in aContactRecord.ContactForm_Submissions)
                        {
                            string sTimeStamp = aContactRecord.getStringValueFromValue(ContactForm_Submission.Json["timestamp"].ToString());

                            if (Convert.ToInt64(sTimeStamp) > Convert.ToInt64(strLast_Conversion_Date))
                            {
                                strFormName = ContactForm_Submission.Title;
                                strLast_Conversion_Date = aContactRecord.getStringValueFromValue(ContactForm_Submission.Json["timestamp"].ToString());
                            }

                            if (strFirst_Conversion_Date == "" || Convert.ToInt64(sTimeStamp) < Convert.ToInt64(strFirst_Conversion_Date))
                                strFirst_Conversion_Date = aContactRecord.getStringValueFromValue(ContactForm_Submission.Json["timestamp"].ToString());
                        }

                    }

                    if (leadBase == null)
                    {
                        // add lead to crm
                        ewarebase[] CRMBase = new ewarebase[1];
                        lead CRMLead = new lead();

                        CRMBase[0] = setLeadFields(CRMLead, aContactRecord, true);

                        try
                        {
                            addresult CRMAddResult = binding.add("Lead", CRMBase); //new ewarebase[1]{CRMLead});

                            for (int ii = 0; ii < CRMAddResult.records.Length; ii++)
                            {
                                crmid id = (crmid)CRMAddResult.records[ii];

                                insertContactHubspotForm_SubmissionRecord(id.crmid1, aContactRecord);
                            }

                            hubSpotGuids.Add(hubSpotVid);
                        }
                        catch (SoapHeaderException e)
                        {
                            //string msg = e.Message;
                            ULogging.writeToErrorLog(AppGlobal.getAppLogger(), "SageCRM Logon Exception: hubSpotVid = " + hubSpotVid + " - " + e.Message);
                        }

                    }
                    else
                    {
                        // if lead already exists, update LeadConversionEvents field
                        lead CRMLead = (lead)leadBase[0];
                        ewarebase[] leadList = new ewarebase[1];
                        leadList[0] = setLeadFields(CRMLead, aContactRecord, false);

                        try
                        {
                            updateresult CRMUpdateResult = binding.update("Lead", new ewarebase[] { CRMLead });

                            if (CRMUpdateResult.updatesuccess == true)
                            {
                                for (int ii = 0; ii < leadList.Length; ii++)
                                {
                                    lead CRMLeadRecord = (lead)leadList[ii];

                                    insertContactHubspotForm_SubmissionRecord(CRMLeadRecord.leadid, aContactRecord);
                                }
                            }
                        }
                        catch (SoapHeaderException e)
                        {
                            //string msg = e.Message;
                            ULogging.writeToErrorLog(AppGlobal.getAppLogger(), "SageCRM Logon Exception: hubSpotVid = " + hubSpotVid + " - " + e.Message);
                        }

                        hubSpotGuids.Add(hubSpotVid);
                    }
                }
            }

            //saveProcessedLeads(ds);
            saveProcessedRecords(ds, "hubspotleadstaging");
            logoff();

            //ADD CODE TO UPDATE STAGING WITH LEAD ID
            updateStagedLeadsWithParentId(hubSpotGuids, "LEAD", "LEAD_LEADID", "LEAD_HUBSPOTGUID");

            return 0;
        }
Exemplo n.º 2
0
        //***** MHM Contacts *************//
        private int pushLeadsToCRM()
        {
            login(); // performs web service (SOAP) login to Sage CRM

            Dictionary<string, int> trimMap = getTrimMap(getMap("Lead"));

            string description = "" + ConfigurationManager.AppSettings.Get("lead_description");
            string stage = "" + ConfigurationManager.AppSettings.Get("lead_stage");
            string source = "" + ConfigurationManager.AppSettings.Get("lead_source");
            string channelId = "" + ConfigurationManager.AppSettings.Get("SageCRMChannelId");
            ArrayList hubSpotGuids = new ArrayList();

            DataSet ds = getLeadsToProcess(); // select * from HubSpotLeadStaging where Processed_Timestamp is null

            for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                HubSpotLead leadRecord = new HubSpotLead(ds.Tables[0].Rows[i]["JSON_Data"].ToString());
                HubSpotLeadConversionEvent leadConversionEvent;
                string sFormName = "";
                int recordIndex = 0;
                if (leadRecord.LeadConversionEvents.Count > 0)
                {
                    leadConversionEvent = (HubSpotLeadConversionEvent)leadRecord.LeadConversionEvents[recordIndex];
                    sFormName = leadConversionEvent.getStringValue("formName");
                }

                HubSpotLeadAnalyticDetails analyticalDetails = leadRecord.AnalyticDetails;

                ds.Tables[0].Rows[i]["Processed_Timestamp"] = SLX_Data.getNewTimestamp();

                //this is where we check to see if the hubspot lead guid exists in crm lead table.
                //if not then we add lead to crm
                string hubSpotGuid = leadRecord.getStringValue("guid");

                //ULogging.writeToDebugLog(AppGlobal.getAppLogger(), "getLeadsToProcess = " + hubSpotGuid);

                //this is where we check to see if the hubspot lead guid exists in crm lead table.
                //if not then we add lead to crm

                string sqlQuery = "lead_deleted is null and lead_hubspotguid = '" + hubSpotGuid + "'";
                queryresult entityResult = binding.query(sqlQuery, "Lead");
                ewarebase[] leadBase = entityResult.records;

                if (leadBase == null)
                {
                    // add lead to crm
                    ewarebase[] CRMBase = new ewarebase[1];
                    lead CRMLead = new lead();

                    // 201-06-10 NEED TO CLEANUP THE TRIM CALLS ON THE VARIOUS FIELDS
                    CRMLead.closed = leadRecord.getDateTimeValueInLocalTime("closedAt");
                    CRMLead.companyname = getTrimmedValue(trimMap, "COMPANYNAME", leadRecord.getStringValue("company"));
                    CRMLead.companycountry = getTrimmedValue(trimMap, "COMPANYCOUNTRY", leadRecord.getStringValue("country"));
                    //object country = getPicklistValue(typeof(lead_companycountry), leadRecord.getStringValue("country"));

                    //if (country != null)
                    //{
                    //    CRMLead.companycountry = (lead_companycountry)country;
                    //}

                    CRMLead.personemail = getTrimmedValue(trimMap, "PERSONEMAIL", leadRecord.getStringValue("email"));
                    CRMLead.personfaxareacode = getTrimmedValue(trimMap, "PERSONFAXAREACODE", UPhone.getFormattedAreaCode(leadRecord.getStringValue("fax"), null));
                    CRMLead.personfaxnumber = getTrimmedValue(trimMap, "PERSONFAXNUMBER", UPhone.getFormattedPhoneNumberWithoutAreaCode(leadRecord.getStringValue("fax"), null));
                    CRMLead.personfirstname = getTrimmedValue(trimMap, "PERSONFIRSTNAME", leadRecord.getStringValue("firstName"));
                    CRMLead.hubspot1stconversiondate = leadRecord.getDateTimeValueInLocalTime("firstVisitSetAt");
                    CRMLead.hubspot1stconversiondateSpecified = true;
                    CRMLead.hubspotfoundsitevia = getTrimmedValue(trimMap, "HUBSPOTFOUNDSITEVIA", leadRecord.getStringValue("foundVia"));
                    CRMLead.hubspotguid = getTrimmedValue(trimMap, "HUBSPOTGUID", leadRecord.getStringValue("guid"));
                    CRMLead.companyindustry = getTrimmedValue(trimMap, "COMPANYINDUSTRY", leadRecord.getStringValue("industry"));
                    //object industry = getPicklistValue(typeof(lead_companyindustry), leadRecord.getStringValue("industry"));

                    //if (industry != null)
                    //{
                    //    CRMLead.companyindustry = (lead_companyindustry)industry;
                    //}

                    CRMLead.hubspotipaddress = getTrimmedValue(trimMap, "HUBSPOTIPADDRESS", leadRecord.getStringValue("ipAddress"));
                    CRMLead.persontitle = getTrimmedValue(trimMap, "PERSONTITLE", leadRecord.getStringValue("jobTitle"));
                    CRMLead.hubspotrecentconvertdate = leadRecord.getDateTimeValueInLocalTime("lastConvertedAt");
                    CRMLead.hubspotrecentconvertdateSpecified = true;
                    CRMLead.personlastname = getTrimmedValue(trimMap, "PERSONLASTNAME", leadRecord.getStringValue("lastName"));
                    CRMLead.hubspotleaddetail = leadRecord.getStringValue("message");
                    CRMLead.personphoneareacode = getTrimmedValue(trimMap, "PERSONPHONEAREACODE", UPhone.getFormattedAreaCode(leadRecord.getStringValue("phone"), null));
                    CRMLead.personphonenumber = getTrimmedValue(trimMap, "PERSONPHONENUMBER", UPhone.getFormattedPhoneNumberWithoutAreaCode(leadRecord.getStringValue("phone"), null));
                    CRMLead.personsalutation = getTrimmedValue(trimMap, "PERSONSALUTATION", leadRecord.getStringValue("salutation"));
                    //object salutation = getPicklistValue(typeof(lead_personsalutation), leadRecord.getStringValue("salutation"));

                    //if (salutation != null)
                    //{
                    //    CRMLead.personsalutation = (lead_personsalutation)salutation;
                    //}

                    CRMLead.hubspotleadgrade = getTrimmedValue(trimMap, "HUBSPOTLEADGRADE", leadRecord.getStringValue("score")); //May want to change to decimal like SLX. Don't forget to set Specified flag to true
                    CRMLead.companystate = getTrimmedValue(trimMap, "COMPANYSTATE", leadRecord.getStringValue("state"));
                    CRMLead.companywebsite = getTrimmedValue(trimMap, "COMPANYWEBSITE", leadRecord.getStringValue("website"));
                    CRMLead.companypostcode = getTrimmedValue(trimMap, "COMPANYPOSTCODE", leadRecord.getStringValue("zip"));
                    CRMLead.companycity = getTrimmedValue(trimMap, "COMPANYCITY", leadRecord.getStringValue("city"));
                    CRMLead.description = description;
                    CRMLead.source = source;
                    //object leadSource = getPicklistValue(typeof(lead_source), source);

                    //if (leadSource != null)
                    //{
                    //    CRMLead.source = (lead_source)leadSource;
                    //}

                    CRMLead.stage = stage;
                    //object leadStage = getPicklistValue(typeof(lead_stage), stage);

                    //if(leadStage != null)
                    //{
                    //    CRMLead.stage = (lead_stage)leadStage;
                    //}

                    CRMLead.opened = leadRecord.getDateTimeValueInLocalTime("insertedAt");
                    CRMLead.openedSpecified = true;
                    CRMLead.details = leadRecord.getStringValue("message");
                    CRMLead.hubspotinsertedat = leadRecord.getDateTimeValueInLocalTime("insertedAt");
                    CRMLead.hubspotinsertedatSpecified = true;
                    CRMLead.hubspotfirsturl = leadRecord.getStringValue("firstUrl");
                    CRMLead.hubspotfullfoundviastring = leadRecord.getStringValue("fullFoundViaString");
                    CRMLead.hubspottwitterhandle = getTrimmedValue(trimMap, "HUBSPOTTWITTERHANDLE", leadRecord.getStringValue("twitterHandle"));
                    CRMLead.hubspotformname = getTrimmedValue(trimMap, "HUBSPOTFORMNAME", sFormName);
                    CRMLead.hubspotconversionevents = leadRecord.getIntegerValue("numConversionEvents");
                    CRMLead.hubspotconversioneventsSpecified = true;
                    CRMLead.hubspotpublicleadlink = getTrimmedValue(trimMap, "HUBSPOTPUBLICLEADLINK", leadRecord.getStringValue("publicLeadLink"));
                    CRMLead.hubspotfirstvisit = leadRecord.getDateTimeValueInLocalTime("firstVisitSetAt");
                    CRMLead.hubspotfirstvisitSpecified = true;
                    //CRMLead.assigneduserid = System.Convert.ToInt32(UConfig.getAppConfigValue("lead_assigneduserid", false));
                    CRMLead.assigneduserid = System.Convert.ToInt32(UConfig.getAppConfigValue("userid", false));
                    CRMLead.assigneduseridSpecified = true;

                    if (String.IsNullOrEmpty(channelId) == false)
                    {
                        CRMLead.channelid = System.Convert.ToInt32(channelId);
                        CRMLead.channelidSpecified = true;
                    }

                    CRMLead.hubspotwebsitevisits = analyticalDetails.getIntegerValue("visitCount");
                    CRMLead.hubspotwebsitevisitsSpecified = true;
                    CRMLead.hubspottotalpageviews = analyticalDetails.getIntegerValue("pageViewCount");
                    CRMLead.hubspottotalpageviewsSpecified = true;
                    CRMLead.hubspotaveragepageviews = Convert.ToDouble(getAveragePagesViewed(analyticalDetails.getIntegerValue("visitCount"), analyticalDetails.getIntegerValue("pageViewCount")));
                    CRMLead.hubspotaveragepageviewsSpecified = true;

                    CRMBase[0] = CRMLead;

                    try
                    {
                        addresult CRMAddResult = binding.add("Lead", CRMBase); //new ewarebase[1]{CRMLead});

                        for (int ii = 0; ii < CRMAddResult.records.Length; ii++)
                        {
                            crmid id = (crmid)CRMAddResult.records[ii];

                            insertHubspotLeadConversionEventRecord(id.crmid1, leadRecord);
                        }

                        hubSpotGuids.Add(hubSpotGuid);
                    }
                    catch (SoapHeaderException e)
                    {
                        //string msg = e.Message;
                        ULogging.writeToErrorLog(AppGlobal.getAppLogger(), "SageCRM Logon Exception: hubSpotGuid = " +hubSpotGuid + " - " + e.Message);
                    }
                }
                else
                {
                    // if lead already exists, update LeadConversionEvents field
                    lead CRMLead = (lead)leadBase[0];

                    CRMLead.hubspotformname = getTrimmedValue(trimMap, "HUBSPOTFORMNAME", sFormName);
                    CRMLead.hubspotleadconvertevents = leadRecord.getStringValue("leadConversionEvents");
                    CRMLead.hubspotrecentconvertdate = leadRecord.getDateTimeValueInLocalTime("lastConvertedAt");
                    CRMLead.hubspotrecentconvertdateSpecified = true;
                    CRMLead.hubspotconversionevents = leadRecord.getIntegerValue("numConversionEvents");
                    CRMLead.hubspotconversioneventsSpecified = true;
                    CRMLead.hubspotwebsitevisits = analyticalDetails.getIntegerValue("visitCount");
                    CRMLead.hubspotwebsitevisitsSpecified = true;
                    CRMLead.hubspottotalpageviews = analyticalDetails.getIntegerValue("pageViewCount");
                    CRMLead.hubspottotalpageviewsSpecified = true;
                    CRMLead.hubspotaveragepageviews = Convert.ToDouble(getAveragePagesViewed(analyticalDetails.getIntegerValue("visitCount"), analyticalDetails.getIntegerValue("pageViewCount")));
                    CRMLead.hubspotaveragepageviewsSpecified = true;
                    CRMLead.hubspotfoundsitevia = getTrimmedValue(trimMap, "HUBSPOTFOUNDSITEVIA", leadRecord.getStringValue("foundVia"));
                    CRMLead.hubspotfullfoundviastring = leadRecord.getStringValue("fullFoundViaString");
                    CRMLead.hubspotleadgrade = getTrimmedValue(trimMap, "HUBSPOTLEADGRADE", leadRecord.getStringValue("score")); //May want to change to decimal like SLX. Don't forget to set Specified flag to true

                    ewarebase[] leadList = new ewarebase[1];

                    leadList[0] = CRMLead;

                    try
                    {
                        updateresult CRMUpdateResult = binding.update("Lead", new ewarebase[]{CRMLead});

                        if (CRMUpdateResult.updatesuccess == true)
                        {
                            for (int ii = 0; ii < leadList.Length; ii++)
                            {
                                lead CRMLeadRecord = (lead)leadList[ii];

                                insertHubspotLeadConversionEventRecord(CRMLeadRecord.leadid, leadRecord);
                            }
                        }
                    }
                    catch (SoapHeaderException e)
                    {
                        //string msg = e.Message;
                        ULogging.writeToErrorLog(AppGlobal.getAppLogger(), "SageCRM Logon Exception: hubSpotGuid = " + hubSpotGuid + " - " + e.Message);
                    }

                    hubSpotGuids.Add(hubSpotGuid);
                }
            }

            //saveProcessedLeads(ds);
            saveProcessedRecords(ds, "hubspotleadstaging");
            logoff();

            //ADD CODE TO UPDATE STAGING WITH LEAD ID
            updateStagedLeadsWithParentId(hubSpotGuids, "LEAD", "LEAD_LEADID", "LEAD_HUBSPOTGUID");

            return 0;
        }
Exemplo n.º 3
0
        private lead setLeadFields(lead CRMLead, HubSpotLead aContactRecord, bool addRecord)
        {
            string strValue;
            HubSpotMapItem item;

            // When adding Lead
            if (addRecord)
            {
                //CRMLead.hubspotguid = aContactRecord.ContactDetailRecord.getStringValue("vid");
                CRMLead.description = strDescription;
                CRMLead.source = strSource;
                CRMLead.stage = strStage;
                CRMLead.assigneduserid = System.Convert.ToInt32(UConfig.getAppConfigValue("userid", false));
                CRMLead.assigneduseridSpecified = true;
                CRMLead.hubspotpublicleadlink = getTrimValue(mapLead.getItem("hubspotpublicleadlink"), strPublicLink);

                if (String.IsNullOrEmpty(strChannelId) == false)
                {
                    CRMLead.channelid = System.Convert.ToInt32(strChannelId);
                    CRMLead.channelidSpecified = true;
                }
            }

            // Always update fields
            CRMLead.hubspotguid = aContactRecord.ContactIdentity_Profiles[0].current_Lead_Guid; ;
            CRMLead.hubspotvid = aContactRecord.ContactDetailRecord.getStringValue("vid");
            CRMLead.hubspotrecentupdate = getDateTimeValue(aContactRecord.ContactHeaderRecord.getStringValue("addedAt"));
            CRMLead.hubspotrecentupdateSpecified = true;
            CRMLead.hubspotformname = getTrimValue(mapLead.getItem("HUBSPOTFORMNAME"), strFormName);
            CRMLead.hubspotconversionevents = getIntegerValue(strConversionEvents);
            CRMLead.hubspotconversioneventsSpecified = true;
            CRMLead.hubspotwebsitevisits = getIntegerValue(getTrimValue(mapLead.getItem("hubspotwebsitevisits"), aContactRecord));
            CRMLead.hubspotwebsitevisitsSpecified = true;
            CRMLead.hubspottotalpageviews = getIntegerValue(getTrimValue(mapLead.getItem("hubspottotalpageviews"), aContactRecord));
            CRMLead.hubspottotalpageviewsSpecified = true;
            CRMLead.hubspotaveragepageviews = Convert.ToDouble(getAveragePagesViewed(CRMLead.hubspotwebsitevisits, CRMLead.hubspottotalpageviews));
            CRMLead.hubspotaveragepageviewsSpecified = true;
            CRMLead.hubspotleadgrade = getTrimValue(mapLead.getItem("hubspotleadgrade"), aContactRecord); //May want to change to decimal like SLX. Don't forget to set Specified flag to true
            if (!string.IsNullOrEmpty(strLast_Conversion_Date))
            {
                CRMLead.hubspotrecentconvertdate = getDateTimeValue(strLast_Conversion_Date);
                CRMLead.hubspotrecentconvertdateSpecified = true;
            }
            if (!string.IsNullOrEmpty(strFirst_Conversion_Date))
            {
                CRMLead.hubspot1stconversiondate = getDateTimeValue(strFirst_Conversion_Date);
                CRMLead.hubspot1stconversiondateSpecified = true;
            }

            //CRMLead.hubspotfullfoundviastring = leadRecord.getStringValue("fullFoundViaString");
            //CRMLead.hubspotleadconvertevents = leadRecord.getStringValue("leadConversionEvents");

            // Standard mapping fields

            item = mapLead.getItem("Closed");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && !string.IsNullOrEmpty(getTrimValue(item, aContactRecord)) && (addRecord || item.CrmUpdate))
                CRMLead.closed = getDateTimeValue(getTrimValue(item, aContactRecord));

            item = mapLead.getItem("companyname");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.companyname = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("companycountry");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.companycountry = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("PERSONEMAIL");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.personemail = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("PERSONFAXNUMBER");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
            {
                strValue = aContactRecord.ContactProperties.getContactPropertyStringValue(item.HubSpotFieldName);
                CRMLead.personfaxareacode = UPhone.getFormattedAreaCode(strValue, null);
                CRMLead.personfaxnumber = UPhone.getFormattedPhoneNumberWithoutAreaCode(strValue, null);
            }

            item = mapLead.getItem("PERSONFIRSTNAME");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.personfirstname = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("COMPANYINDUSTRY");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.companyindustry = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("HUBSPOTIPADDRESS");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.hubspotipaddress = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("PERSONTITLE");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.persontitle = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("PERSONLASTNAME");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.personlastname = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("hubspotleaddetail");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
            {
                CRMLead.hubspotleaddetail = getTrimValue(item, aContactRecord);
                CRMLead.details = getTrimValue(item, aContactRecord);
            }

            item = mapLead.getItem("PERSONPHONENUMBER");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
            {
                strValue = aContactRecord.ContactProperties.getContactPropertyStringValue(item.HubSpotFieldName);
                CRMLead.personphoneareacode = UPhone.getFormattedAreaCode(strValue, null);
                CRMLead.personphonenumber = UPhone.getFormattedPhoneNumberWithoutAreaCode(strValue, null);
            }

            item = mapLead.getItem("PERSONSALUTATION");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.personsalutation = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("COMPANYSTATE");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.companystate = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("COMPANYWEBSITE");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.companywebsite = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("COMPANYPOSTCODE");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.companypostcode = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("COMPANYCITY");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.companycity = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("HUBSPOTTWITTERHANDLE");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.hubspottwitterhandle = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("hubspotinsertedat");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && !string.IsNullOrEmpty(getTrimValue(item, aContactRecord)) && (addRecord || item.CrmUpdate))
            {
                CRMLead.hubspotinsertedat = getDateTimeValue(getTrimValue(item, aContactRecord));
                CRMLead.hubspotinsertedatSpecified = true;
                CRMLead.opened = getDateTimeValue(getTrimValue(item, aContactRecord));
                CRMLead.openedSpecified = true;
            }

            item = mapLead.getItem("hubspotfirsturl");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.hubspotfirsturl = getTrimValue(item, aContactRecord);

            item = mapLead.getItem("hubspotfirstvisit");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && !string.IsNullOrEmpty(getTrimValue(item, aContactRecord)) && (addRecord || item.CrmUpdate))
            {
                CRMLead.hubspotfirstvisit = getDateTimeValue(getTrimValue(item, aContactRecord));
                CRMLead.hubspotfirstvisitSpecified = true;
            }

            //CRMLead.hubspotfoundsitevia = getTrimmedValue(trimMap, "HUBSPOTFOUNDSITEVIA", leadRecord.getStringValue("foundVia"));
            item = mapLead.getItem("hubspotfoundsitevia");
            if (!string.IsNullOrEmpty(item.HubSpotFieldName) && (addRecord || item.CrmUpdate))
                CRMLead.hubspotfoundsitevia = getTrimValue(item, aContactRecord);

            return CRMLead;
        }