Lead's phone number listed in task

How can i list the mobile and phone number of the lead in tasks ?

When you create a ā€˜Task’ for a ā€˜Lead’ in the Activities section there’s a natural link-back between both records (Lead to Task & Task to Lead) as shown.

gif

Unless you’re wanting to achieve something entirely different? Can you explain a bit more?

i want to see the phone number directly on the task screen.

i have to call alls tasks, so it will save work and time.

How can i add this field in task view?

This may help:

I have a few ways of doing this. Are you a developer? It’s a little bit of an involved coding task with a number of steps, but it works pretty cleanly. I have a couple of different approaches, one is a an after_retrieve hook to pull the value from the related module into a non-db field and the other is by creating a custom utility function.

If there is an easier way anyone knows, I’m all ears!

yes i have coding knowledge. if you tell me what to change where exactly, i would do it :slight_smile:

Here are my notes, should be enough for you to go on…

In this example I’m populating a ā€œTaskā€ with the related ā€œOpportunityā€ name. In your case your populating the ā€œleadsā€ phone number on the task.

Using an after_retreive Logic Hook

Step 1: Add field to editviewdefs.php (or detailviewdefs.php)

\custom\modules\Tasks\metadata\editviewdefs.php (in this case Tasks is the module)

Add the field in the array like so:

0 => 
		    array(
                'name' => 'non_db_field_c', // Name of the non-db field
                'label' => 'LBL_NON_DB_FIELD_LABEL', // Label for the field
				' displayParams' => array(
						'readonly' => true,
				), // Set the field as non-editable
            ),

Step 2: Add the vardef

\custom\Extension\modules\Tasks\Ext\Vardefs\custom_non_db_field.php (in this case Tasks is the module)

<?php
$dictionary['Task']['fields']['non_db_field_c'] = array(
    'name' => 'non_db_field_c',
    'vname' => 'LBL_NON_DB_FIELD_LABEL',
	'type' => 'readonly', // Set the field type to 'readonly'
	'inline_edit' => 'false', //disable inline edit
    'type' => 'varchar',
    'source' => 'non-db',
    'studio' => false, // Optional: Hide the field in Studio
);

Step 3: Create the Logic Hook

\custom\modules\Tasks\logic_hooks.php (in this case Tasks is the module)

<?php
$hook_array['after_retrieve'][] = array(
    1,
    'PopulateNonDbField',
    'custom/modules/Tasks/PopulateNonDbField.php',
    'PopulateNonDbFieldClass',
    'populateNonDbFieldMethod'
);

Step 4: Create the Logic Hook Class and Method

\custom\modules\Tasks\PopulateNonDbField.php (in this case Tasks is the module)

<?php
if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}

class PopulateNonDbFieldClass
{
    public function populateNonDbFieldMethod($bean, $event, $arguments)
    {
        // Check if the related module is Opportunity
        if ($bean->load_relationship('opportunities') && $bean->opportunities->getBeans()) {
            // Get the related Opportunity's name
            $relatedOpportunity = current($bean->opportunities->getBeans());
            $opportunityName = $relatedOpportunity->name;

            // Populate the non-db field with the Opportunity's name
            $bean->non_db_field_c = $opportunityName;
        }
    }
}

Step 5: Create the custom language file

custom/Extension/modules/Tasks/Ext/Language/ directory.

Create a file named something like en_us.custom_non_db_fields.php (replace en_us with your desired language code) and define the label in the file:

<?php
$mod_strings['LBL_CUSTOM_NON_DB_FIELD_LABEL'] = 'Custom Non-DB Field Label';
1 Like