{"id":9269,"date":"2024-10-05T12:02:37","date_gmt":"2024-10-05T12:02:37","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=9269"},"modified":"2024-10-09T06:07:51","modified_gmt":"2024-10-09T06:07:51","slug":"how-to-show-related-emails-in-vtiger-compose-popup","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/how-to-show-related-emails-in-vtiger-compose-popup\/","title":{"rendered":"How to Show Related Emails in Vtiger Compose Popup"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 1,162<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p>To show related emails in vtiger the <strong>popup for composeMailData<\/strong>, you will need to customize the functionality by modifying the code that controls the email popup and related data retrieval. Here&#8217;s a high-level guide on how to achieve this:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Locate the Compose Email Popup Code<\/strong><\/h3>\n\n\n\n<p>The <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">composeMailData<\/mark><\/code> popup in Vtiger is part of the Mail Manager module. You need to modify the code that renders the popup and fetches related data.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The relevant file for handling the email compose popup can be found in:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">modules\/Emails\/Emails.js<\/mark><\/code><\/code><\/pre>\n\n\n\n<p>This file controls the JavaScript functionality for handling email popups and actions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Modify the Backend Logic<\/strong><\/h3>\n\n\n\n<p>In the backend, you&#8217;ll need to extend the logic to fetch related emails based on the context (e.g., related contact, organization, etc.). This can be done by modifying the controller that fetches email data.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Locate the file:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">modules\/Emails\/actions\/ComposeEmail.php<\/mark><\/code><\/code><\/pre>\n\n\n\n<p>This file handles the logic for fetching email data when opening the compose email popup.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Modify this file to include a function that queries related emails. For example, if you want to fetch emails related to a contact or an organization, you would perform a database query like:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">$relatedEmails = Vtiger_Record_Model::getRelatedEmails($recordId, $moduleName);<\/mark><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Create a Function to Retrieve Related Emails<\/strong><\/h3>\n\n\n\n<p>You can write a custom function to retrieve the related emails based on the record ID or module (e.g., Contacts, Leads, etc.). For instance:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">public function getRelatedEmails($recordId, $moduleName) {\n      $db = PearDatabase::getInstance();\n      $query = \"SELECT * FROM vtiger_emaildetails\n                WHERE parent_id = ? AND parent_type = ?\";\n      $result = $db-&gt;pquery($query, array($recordId, $moduleName));\n\n      $emails = array();\n      while ($row = $db-&gt;fetch_array($result)) {\n          $emails&#91;] = $row;\n      }\n\n      return $emails;\n  }<\/mark><\/code><\/code><\/pre>\n\n\n\n<p>This function will return a list of emails related to the specific record.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Pass Related Emails to the Frontend<\/strong><\/h3>\n\n\n\n<p>Once you have the related emails, pass them to the frontend by modifying the response that sends data to the <code><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">composeMailData<\/mark><\/code> popup. You can include the list of emails as part of the response array:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">$viewer-&gt;assign('RELATED_EMAILS', $relatedEmails);<\/mark><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>Display Related Emails in the Popup<\/strong><\/h3>\n\n\n\n<p>In the frontend, modify the popup template to display the related emails. You can find the relevant template file in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">layouts\/v7\/modules\/Emails\/ComposeEmail.tpl<\/mark><\/code><\/code><\/pre>\n\n\n\n<p>Add a section in the template to display the related emails. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  <code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&lt;div class=\"related-emails-section\"&gt;\n      &lt;h4&gt;Related Emails&lt;\/h4&gt;\n      &lt;ul&gt;\n          {foreach from=$RELATED_EMAILS item=email}\n              &lt;li&gt;{$email.subject} - {$email.sentdate}&lt;\/li&gt;\n          {\/foreach}\n      &lt;\/ul&gt;\n  &lt;\/div&gt;<\/mark><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>Test Your Changes<\/strong><\/h3>\n\n\n\n<p>After making these modifications:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Clear the cache to ensure changes are reflected.<\/li>\n\n\n\n<li>Test the email compose popup and check if the related emails are being displayed correctly.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Optional: <strong>Use Vtiger&#8217;s Widget for Related Records<\/strong><\/h3>\n\n\n\n<p>If you want a more reusable solution, consider using Vtiger&#8217;s related record widgets to display related emails. This would involve utilizing Vtiger&#8217;s built-in functionality to show related records in popups.<\/p>\n\n\n\n<p>By following these steps, you can customize the Vtiger system to show related emails in the compose email popup.<\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>If you want to show all related emails in the vtiger then the\u00a0popup, especially for composeMailData, you just want to tailor the working by simply making little changes in the code that simply controls the email popup and all associated data retrieval. By having the <a href=\"https:\/\/www.infinitivehost.com\/managed-vtiger-solutions\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\"><strong>best Vtiger hosting solutions<\/strong><\/mark><\/a>, follow the above-mentioned steps to make changes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1,162 Views To show related emails in vtiger the popup for composeMailData, you will need to customize the functionality by modifying the code that controls the email popup and related data retrieval. Here&#8217;s a high-level guide on how to achieve this: 1. Locate the Compose Email Popup Code The composeMailData popup in Vtiger is part [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[204],"tags":[],"class_list":["post-9269","post","type-post","status-publish","format-standard","hentry","category-vtiger-solutions"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=9269"}],"version-history":[{"count":2,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9269\/revisions"}],"predecessor-version":[{"id":9294,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9269\/revisions\/9294"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=9269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=9269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=9269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}