/// <remarks/> public void addresourceAsync(string entityname, ewarebase[] records, object userState) { if ((this.addresourceOperationCompleted == null)) { this.addresourceOperationCompleted = new System.Threading.SendOrPostCallback(this.OnaddresourceOperationCompleted); } this.InvokeAsync("addresource", new object[] { entityname, records}, this.addresourceOperationCompleted, userState); }
/// <remarks/> public void addresourceAsync(string entityname, ewarebase[] records) { this.addresourceAsync(entityname, records, null); }
/// <remarks/> public void deleteAsync(string entityname, ewarebase[] records) { this.deleteAsync(entityname, records, null); }
/// <remarks/> public void updaterecordAsync(string entityname, ewarebase[] records) { this.updaterecordAsync(entityname, records, null); }
//***** 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; }
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; }