public void Save(string strExcludedEmails = "") { try { ArrayList arrCRMContacts = GetValidContactIDs(strExcludedEmails); if (arrCRMContacts.Count > 0) { List<RESTObjects.eNameValue> emailData = new List<RESTObjects.eNameValue>(); emailData.Add(new RESTObjects.eNameValue() { name = "from_addr", value = From }); emailData.Add(new RESTObjects.eNameValue() { name = "to_addrs", value = To.Replace("\n", "") }); emailData.Add(new RESTObjects.eNameValue() { name = "name", value = Subject }); emailData.Add(new RESTObjects.eNameValue() { name = "description", value = Body }); emailData.Add(new RESTObjects.eNameValue() { name = "description_html", value = HTMLBody }); emailData.Add(new RESTObjects.eNameValue() { name = "assigned_user_id", value = clsSuiteCRMHelper.GetUserId() }); emailData.Add(new RESTObjects.eNameValue() { name = "status", value = "archived" }); object contactData = new { @session = SuiteCRMUserSession.id, @module_name = "Emails", @name_value_list = emailData }; var emailResult = clsGlobals.GetResponse<RESTObjects.eNewSetEntryResult>("set_entry", contactData); foreach (string strContactID in arrCRMContacts) { object contacRelationshipData = new { @session = SuiteCRMUserSession.id, @module_name = "Contacts", @module_id = strContactID, @link_field_name = "emails", @related_ids = new string[] { emailResult.id } }; var relResult = clsGlobals.GetResponse<RESTObjects.eNewSetRelationshipListResult>("set_relationship", contacRelationshipData); } //Attachments foreach (clsEmailAttachments objAttachment in Attachments) { //Initialize AddIn attachment List<RESTObjects.eNameValue> initNoteData = new List<RESTObjects.eNameValue>(); initNoteData.Add(new RESTObjects.eNameValue() { name = "name", value = objAttachment.DisplayName }); object initNoteDataWebFormat = new { @session = SuiteCRMUserSession.id, @module_name = "Notes", @name_value_list = initNoteData }; var res = clsGlobals.GetResponse<RESTObjects.eNewSetEntryResult>("set_entry", initNoteDataWebFormat); //upload the attachment RESTObjects.eNewNoteAttachment attachment = new RESTObjects.eNewNoteAttachment(); attachment.ID = res.id; attachment.FileName = objAttachment.DisplayName; attachment.FileCotent = objAttachment.FileContentInBase64String; object attachmentDataWebFormat = new { @session = SuiteCRMUserSession.id, @note = attachment }; var attachmentResult = clsGlobals.GetResponse<RESTObjects.eNewSetEntryResult>("set_note_attachment", attachmentDataWebFormat); //Relate the email and the attachment object contacRelationshipData = new { @session = SuiteCRMUserSession.id, @module_name = "Emails", @module_id = emailResult.id, @link_field_name = "notes", @related_ids = new string[] { attachmentResult.id } }; var rel = clsGlobals.GetResponse<RESTObjects.eNewSetRelationshipListResult>("set_relationship", contacRelationshipData); } } } catch (Exception ex) { string strLog; strLog = "------------------" + System.DateTime.Now.ToString() + "-----------------\n"; strLog += "clsEmailArchive.Save method General Exception:\n"; strLog += "Message:" + ex.Message + "\n"; strLog += "Source:" + ex.Source + "\n"; strLog += "StackTrace:" + ex.StackTrace + "\n"; strLog += "HResult:" + ex.HResult.ToString() + "\n"; strLog += "Inputs:" + "\n"; strLog += "Data:" + this.ToString() + "\n"; strLog += "-------------------------------------------------------------------------\n"; clsSuiteCRMHelper.WriteLog(strLog); throw ex; } }
public void Save(string strExcludedEmails = "") { try { ArrayList arrCRMContacts = GetValidContactIDs(strExcludedEmails); if (arrCRMContacts.Count > 0) { List <RESTObjects.eNameValue> emailData = new List <RESTObjects.eNameValue>(); emailData.Add(new RESTObjects.eNameValue() { name = "from_addr", value = From }); emailData.Add(new RESTObjects.eNameValue() { name = "to_addrs", value = To.Replace("\n", "") }); emailData.Add(new RESTObjects.eNameValue() { name = "name", value = Subject }); emailData.Add(new RESTObjects.eNameValue() { name = "description", value = Body }); emailData.Add(new RESTObjects.eNameValue() { name = "description_html", value = HTMLBody }); emailData.Add(new RESTObjects.eNameValue() { name = "assigned_user_id", value = clsSuiteCRMHelper.GetUserId() }); emailData.Add(new RESTObjects.eNameValue() { name = "status", value = "archived" }); object contactData = new { @session = SuiteCRMUserSession.id, @module_name = "Emails", @name_value_list = emailData }; var emailResult = clsGlobals.GetResponse <RESTObjects.eNewSetEntryResult>("set_entry", contactData); foreach (string strContactID in arrCRMContacts) { object contacRelationshipData = new { @session = SuiteCRMUserSession.id, @module_name = "Contacts", @module_id = strContactID, @link_field_name = "emails", @related_ids = new string[] { emailResult.id } }; var relResult = clsGlobals.GetResponse <RESTObjects.eNewSetRelationshipListResult>("set_relationship", contacRelationshipData); } //Attachments foreach (clsEmailAttachments objAttachment in Attachments) { //Initialize AddIn attachment List <RESTObjects.eNameValue> initNoteData = new List <RESTObjects.eNameValue>(); initNoteData.Add(new RESTObjects.eNameValue() { name = "name", value = objAttachment.DisplayName }); object initNoteDataWebFormat = new { @session = SuiteCRMUserSession.id, @module_name = "Notes", @name_value_list = initNoteData }; var res = clsGlobals.GetResponse <RESTObjects.eNewSetEntryResult>("set_entry", initNoteDataWebFormat); //upload the attachment RESTObjects.eNewNoteAttachment attachment = new RESTObjects.eNewNoteAttachment(); attachment.ID = res.id; attachment.FileName = objAttachment.DisplayName; attachment.FileCotent = objAttachment.FileContentInBase64String; object attachmentDataWebFormat = new { @session = SuiteCRMUserSession.id, @note = attachment }; var attachmentResult = clsGlobals.GetResponse <RESTObjects.eNewSetEntryResult>("set_note_attachment", attachmentDataWebFormat); //Relate the email and the attachment object contacRelationshipData = new { @session = SuiteCRMUserSession.id, @module_name = "Emails", @module_id = emailResult.id, @link_field_name = "notes", @related_ids = new string[] { attachmentResult.id } }; var rel = clsGlobals.GetResponse <RESTObjects.eNewSetRelationshipListResult>("set_relationship", contacRelationshipData); } } } catch (Exception ex) { string strLog; strLog = "------------------" + System.DateTime.Now.ToString() + "-----------------\n"; strLog += "clsEmailArchive.Save method General Exception:\n"; strLog += "Message:" + ex.Message + "\n"; strLog += "Source:" + ex.Source + "\n"; strLog += "StackTrace:" + ex.StackTrace + "\n"; strLog += "HResult:" + ex.HResult.ToString() + "\n"; strLog += "Inputs:" + "\n"; strLog += "Data:" + this.ToString() + "\n"; strLog += "-------------------------------------------------------------------------\n"; clsSuiteCRMHelper.WriteLog(strLog); throw ex; } }