Create Contracts from Email

Hi,
how can i recreate “Create Contracts” from Email Detail View just like for Opportunities or Case?

Many Thanks

Hey,

I don’t think it can be done without custom code, but you might be able to add an option to that Dropdown fairly easily

Copy the file found at:
modules/Emails/metadata/detailviewdefs.php

and paste it in the custom Directory:
custom/modules/Emails/metadata/detailviewdefs.php
(Feel free to create these folders if not found)

Then, you can add a custom action to that Actions Menu through this file

In this new custom file, at roughly line ~81, add the following new “array(…” block:

 array(
                    'customCode' => '<input type=button onclick="openQuickCreateModal(\'AOS_Contracts\',\'&name={$bean->name}\',\'{$bean->from_addr_name}\');" value="{$MOD.LBL_CREATE} {$APP.LBL_EMAIL_QC_CONTRACTS}">'
                        . '<input type="hidden" id="parentEmailId" name="parentEmailId" value="{$bean->id}">'
                ),

So it will go from this:

To something like this:

Each of these “array(…” blocks is an option on the Dropdown, so this will add a new one, that points to the Contracts Module.
(However, we still need to add a label for this button)


So, create a new language file in the location, if it does not already exist:
custom/include/language/en_us.lang.php

In this, add the following:

<?php
$app_strings['LBL_EMAIL_QC_CONTRACTS'] = 'Contract';

Then, once both snippets above have been added, go to the CRM and run a Quick Repair and Rebuild

Then, you should see a “Create Contract” option on that button
image

Hopefully the above steps make sense!

As Contracts doesn’t have the same Email functionality as the other modules, (Opportunities/Leads), I’m not sure if it will behave the same

But this button should let you create Contracts from here

Let us know if you have any issues :slight_smile:

Well seems to work!!!
Thanks

Now i will try to reproduce it to create record in my custom module, however:
replacing “Aos_Contract” in custom code with my custom module the Create modal appear with right fields definition, but when i save it i received the following error(but the record is saved):
PHP Notice: Undefined property: Email::$cdz_dropdown in /var/www/html/SuiteCRM-7.10.29/modules/Emails/EmailsController.php on line 223, referer: http://10.110.1.129/SuiteCRM-7.10.29/index.php?module=Emails&action=DetailView&record=384e0846-ee1a-465d-036c-5fb64c939f71
[Fri Nov 20 19:28:29.385762 2020] [php7:error] [pid 6170] [client 10.110.1.100:53428] PHP Fatal error: Uncaught Error: Call to a member function add() on null in /var/www/html/SuiteCRM-7.10.29/modules/Emails/EmailsController.php:223\nStack trace:\n#0 /var/www/html/SuiteCRM-7.10.29/include/MVC/Controller/SugarController.php(525): EmailsController->action_QuickCreate()\n#1 /var/www/html/SuiteCRM-7.10.29/include/MVC/Controller/SugarController.php(494): SugarController->do_action()\n#2 /var/www/html/SuiteCRM-7.10.29/include/MVC/Controller/SugarController.php(468): SugarController->handle_action()\n#3 /var/www/html/SuiteCRM-7.10.29/include/MVC/Controller/SugarController.php(373): SugarController->process()\n#4 /var/www/html/SuiteCRM-7.10.29/include/MVC/SugarApplication.php(113): SugarController->execute()\n#5 /var/www/html/SuiteCRM-7.10.29/index.php(52): SugarApplication->execute()\n#6 {main}\n thrown in /var/www/html/SuiteCRM-7.10.29/modules/Emails/EmailsController.php on line 223, referer: http://10.110.1.129/SuiteCRM-7.10.29/index.php?module=Emails&action=DetailView&record=384e0846-ee1a-465d-036c-5fb64c939f71

Thanks

Hey,

From that Fatal error, it looks like it cannot relate the Email Record to your new Custom Module Record

Does your Custom Module use Emails, by chance?

I think that Custom Modules are built differently to the Stock modules, in regards to relationships
So it may be that Module Builder/Studio simply won’t have built the necessary relationships for this functionality
(Especially as the Action of creating Custom Module records from Emails did not exist in the first place, until we added it)


You may be able to try adding Email functionality to your Custom Module, as per:
https://www.rolustech.com/blog/how-to-create-email-field-in-custom-module
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.2/Cookbook/Adding_the_Email_Field_to_a_Bean/index.html

However, these blogs refer to SugarCRM so some things may differ, and there is no guarantee that this would resolve the error :confused:


Interestingly, I have created a Custom Person-type module, and am able to create Records from Email
And this Error does not appear in the Log…

What Type of module was your Custom module?

Hello,
currently the module does not use email and in my test is “AOS_Contracts”.
The goal is to permit the users to create Contracts from email which will be linked as activities in new Contract created(subpanel) to keep track of the task done by themselves.

So in this scenario having Email in Contracts could not have much sense and also builtin Opportunities(which “Create Opportunity” button is already present in Email Detailviewdefs) is working without email field or does it have any hidden behavior?

Thanks

Hey,

Sorry, im not well versed in how Emails works in the back-end, but I’ve had a look

It seems like there is a stock relationship between Opportunitues and Emails in the CRM

These are defined in files like:
modules/Opportunities/vardefs.php
modules/Emails/vardefs.php
metadata/emails_beansMetaData.php

(If you search for “emails_opportunities_rel” in the CRM files)

Contracts does have some Email relationships in both
modules/AOS_Contracts/vardefs.php
modules/Emails/vardefs.php

But it looks like Contracts is not mentioned in the file:
metadata/emails_beansMetaData.php

So, even from that small sample, it does seem like the Opportunities module has some back-end Email functionality, that Contracts does not.

I’ve tried adding an entry for Contracts into this file myself, to see what happens, but have had no luck I’m afraid.
I’ve been hitting Dead-ends so far, but I’ll keep investigating to try and find a solution

Perhaps another user has some idea of what it would take to hook Contracts/Emails up to work like Leads/Contacts/Opps ?
(Or if it is perhaps not possible without large-scale system changes)


As a side-note, it does sound like a useful expansion to the Emails functionality
(Being able to send to Custom Modules / add Email functionality to non-email modules)
Perhaps it would be worth raising on the Github Project as a suggestion?

I agree with you.
It should be useful to have it, and hopefully with a small effort.
I will dig into it and if someone found the solution it would be great to share with others.

Thanks