Writing a Sugar report on email module.

Is there any field for the body of the email?

Parents
  • Kelly,

    If you have SugarCRM Enterprise or Ultimate editions and are familiar with writing SQL queries, you can create a query that joins the email body into the report.  

    For example, create a standard email type report from the Reports module, when editing the report, in the "Report Details" section check the "Show Query" checkbox and click "Preview". 

    This will display the SQL query of the report at the bottom of the page.

    You can then customize this query to add a join statement to the email_text table that contains the body of the email.

    Click here more information on the database tables and fields.

    Click here for information on Advanced Reporting.

    Here is a basic example of a query that pulls in the email subject, description, and date created data:

    SELECT IFNULL(emails.name,'') emails_name
    ,emails_text.description
    ,emails.date_entered emails_date_entered
    FROM emails
    LEFT join emails_text
    ON emails.id = emails_text.email_id

    WHERE ((1=1))
    AND emails.deleted=0

    Hope this helps.

    Lori

  • Hello Lori!

    We've also encountered a similar road block on 7.9.2.0. In that, we're trying to filter on the related emails_text table > 'from_addr' column.

    We're able to check the 'show query' option, and that does display the query, but we're unable to edit the query behind the report. Was the option to directly the edit the 'show query' removed in later versions?

  • Here is another example of using SQL to pull in additional fields.

    SELECT
      emails.date_entered 'Date Created',
      emails_text.from_addr 'From',
      emails_text.to_addrs 'To',
      emails_text.cc_addrs 'CC',
      emails_text.description 'Body'
    FROM emails
    LEFT JOIN emails_text
    ON emails_text.email_id = emails.id
    WHERE emails.date_entered > '2018-11-01 00:00:00';

    When writing/modifying this SQL, it can help to have a local copy of the instance database to test with. This is easy to if you are hosting the database yourself. If not and are a Sugar Cloud customer, you are able to download a copy of the database backup for local testing by opening a support ticket. Support will then make the backup available as a download from within the Backup module of the cloud instance itself.

  • I apologize for resurrecting a 4 year old post, but I'm having this same issue. We am attempting to extract 700,000+ emails from SugarCRM Professional 10.1.0. I am using Excel because it's what I have access to that I know. I've never touched SQL before I started this process but have some VB.net knowledge, so I understand some programming mechanics. When I attempt to get data via ODBC with either of the snippets inserted into the SQL Statement box, I receive the following error: Details: "ODBC: ERROR [HY000] [Devart][ODBC][Sugar]Object 'emails' does not exist"

    I've compared the code to the schema file on Sugar's site for 10.1.0 and I cannot see the error apidocs.sugarcrm.com/.../index.html. Can someone help? 

  • I connected to the table through the wizard and I am able to see records (partially covered window). I then created a new query not using the wizard and input each snippet as SQL, but neither worked. The errors were the same on each: 

    (I hit OK)

    My workday is almost over, but I'll be chasing this again on Monday and will check back in then. Thank you very much for your help.

    Some specifics: I need to export all emails with their full content, including the body text. I also need to add in the SugarID for the account with which the email is associated, the same ID that shows up in the address bar when viewing a client. As I extract, I'll need to limit the date range within the coding and run multiple queries to have better control over the size of the downloads. I'm downloading 9 years of data, 766530 emails. 

  • Interesting, I had the exact same popup as you had and I didn't get the "Could not add the table" error. Maybe try to query for specific fields and see if that works?

    select id, name from emails;

    If the Microsoft Query is working, then you could probably use that to insert data into excel instead of using Saved Queries? Apologies, unfortunately, this is something related to Excel and I have no idea why it doesn't work. 

    The only alternative that I can suggest is to use a Visual Query Editor tool like MySQL Workbench where you can create a simple DB connection and start running queries out of it. It can also export data to Excel/variety of other formats.

    It's a simple visual tool provided by MySQL itself: https://dev.mysql.com/downloads/workbench/

    And you just need few seconds to connect to a DB and run queries:

    Once you run the query, you can click on "Export" to save it as Excel/CSV etc.

  • Thank you! I have some things I have to complete first, but I'll circle back to this later. Would you be able to help me by tweaking the code to insert the account id and the date parameter field? I'm certain you can do it in a fraction of the time it would take me to look up the parameter specifics and make the changes myself.

  • Sure, happy to help.

    If you're looking at email contents, emails_text is the table that you need. It has From/To/Email Body

    Subject comes from emails.name

    If the emails are sent from Accounts module, the link is established in a table called "emails_beans", with bean_module = 'Accounts'.

    Finally, use the date_sent in emails table to filter when this email was actually sent.

    So combining all three, the query that you need is something like:

    select eb.bean_id as account_id,
    e.id as email_id,
    e.name as subject,
    e.date_sent as date_sent,
    et.from_addr,
    et.to_addrs,
    et.cc_addrs,
    et.description -- Use this or description_html
    from emails e,
    emails_beans eb,
    emails_text et
    where e.id = eb.email_id
    and e.deleted = 0
    and eb.deleted = 0
    and e.id = et.email_id
    and et.deleted = 0
    and eb.bean_module = 'Accounts'
    and e.date_sent between '2020-01-01' and now();
  • Thank you! I'll try this later. I really appreciate your help. 

    Now I need to add SQL to my list of things to teach myself. 

  • Again, thank you for all of your help. I give up with this task at least. No matter what I try, it tells me object Emails does not exist, when I'm looking at an Emails table in SugarCRM and in the Schema list. I've spent enough time on it now that I'm going to recommend we hire someone to help with the extraction of data from SugarCRM.

  • Selection behavior does depends on deployment specifics
    do you have balancing server? is there a number of servers to maintain big database? are their any replications? 

    selecting data from server and user laptop can also matter - on enterprise scale, Sugar database could be deployed on the number of servers, therefore the context of the schema/database should be given for successful selection

    Therefore, you may try to add the schema/database name explicitly into your query to get either data or real response from server
    for Ult/Ent you may use Admin -> Diagnostic Tool to get config of all the servers

    also please note MSQuery is fairly old - 
    it wont allow selecting all the records you expect in the email table
    Agree with Neeraja that that MySQL Workbench would fit better

    All the best, 
    Dmytro

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • You're speaking Greek to me. I have no clue about any of it. I'd quite literally never gone into admin mode on SugarCRM or touched SQL in any form until I started looking at this last week. I've already made the recommendation that our CEO hire someone to tackle the project.

  • Heather,

    I'm very sorry there was requested to do the work with neither investing in Sugar admin learning and certification nor inquiring Sugar Partner to help with probably enterprise-scale solution deployed.

    I can only suppose why they ask you to download emails for 9 years
    Is that for analytics? or company is trying to change the CRM platform?

    I would suggest discussing the challenge with your Sugar Customer Success Manager and maybe to inquire Sugar Partners' expertise to take care of database maintenance and refresh Sugar 

    I suppose CEO may have questions, so please feel free to write to dch@integroscrm.com - as Sugar Partner we implement and support Sugar for more than a decade and would be happy to be of help for your company
    You may find some customers' feedbacks on the website www.integroscrm.com

    Have a nice day,
    Dmytro

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • We converted to another CRM. We were able to move everything else to the new CRM. It's only the emails we've not been able to move.

Reply Children
No Data