Lead convert with default last_name value

I’m using SuiteCRM 8.7.1 and I’m not an expert.

I’ve set “N/D” as default value for last_name field in lead module for the leads without a contact but with only an account.
In lead convert I would like to set empty value for last_name field if the original value is “N/D”.

Can anybody help me? Thanks

Hi,
‘before_save’ logic hook should help.

You can try to achieve this using workflows
In the conditions check if last_name is N/D
And in the actions set the last_name to empty

I tried this solution, but the options for the “Run” field are Always, Only On Save and Only In The Scheduler. I need to make “last_name” field empty only when such field value is N/D in lead convert page.

Run field you should select only on save
There isn’t a explicit condition for leads page
But the condition that last_name = n/d should be sufficient

My expectation is differente

Maybe a javascript could make those I’d like to do. But I don’t know in which file insert the new code.

If you want to make the last_name empty on convert lead page if it is ‘N/D’ on leads detail view, you can change that on convert lead page in this file custom\modules\Leads\views\view.convertlead.php (create the file and extend the class and override the getRecord method.

require_once('modules\Leads\views\view.convertlead.php');
class CustomLeadsViewConvertLead extends ViewConvertLead
{
  protected function getRecord()
    {
        $this->focus = BeanFactory::newBean('Leads');
        if (isset($_REQUEST['record'])) {
            $this->focus->retrieve($_REQUEST['record']);
			if($this->focus->last_name == 'N/D'){
			$this->focus->last_name='';
			}
        }
    }
}

I tried your suggestion but, when I click on Convert Lead, I have the code of the custom\modules\Leads\views\view.convertlead.php file and nothing else, as you can see in the following image

You need to add this to the beginning of your custom file, before the require:

<?php

Sorry I forgot to add php tags in the code. Please add as suggested by PGR. Also you need to run the following command from the root folder.

php bin/console cache:clear

Reload the application in the browser.

This is the new code of the file custom\modules\Leads\views\view.convertlead.php:

<?php
require_once('modules\Leads\views\view.convertlead.php');
class CustomLeadsViewConvertLead extends ViewConvertLead
{
  protected function getRecord()
  {
    $this->focus = BeanFactory::newBean('Leads');
    if (isset($_REQUEST['record'])) {
      $this->focus->retrieve($_REQUEST['record']);
      if($this->focus->last_name == 'N/D'){
        $this->focus->last_name='';
      }
    }
  }
}
?>

Then I executed the command php bin/console cache:clear from the suitecrm root folder.

Now when I try to convert a lead I have a blank page.

The complete goal for me is also to uncheck the “New Contact Or Select Contact” checkbox if last_name = ‘N/D’

We see a blank page for 1 sec or 2 when a legacy view is loaded first time. Did you wait for the convert lead view page to be appeared?

To uncheck ‘Create Contact’, you can try the following

  1. Copy ‘modules\Leads\metadata\convertdefs.php’ at ‘custom\modules\Leads\metadata\convertdefs.php’
  2. Set copyData & required false and comment default_action=create as shown here
$viewdefs['Contacts']['ConvertLead'] = array(
    'copyData' => false,
    'required' => false,
    'select' => "report_to_name",
   //'default_action' => 'create',

image

Yes, I wait many seconds but nothing changed.

Ok for your solution for uncheck ‘Create Contact’, but this must be done only if last_name = ‘N/D’

For unchecking ‘Create Contact’, may be you can create copy of convertdefs file for no contact with copyData, required equal to false and no default_action and override ‘loadDefs’ method in CustomLeadsViewConvertLead class to set the new metadatafile path if last_name is ‘N/D’. I am not sure if this is a good solution because we have two different versions of the defs file.

Just create a custom conversion file. Map the field and just add you logic to populate $lastname.

Below is an example to populate an account field but you can do the same to populate a contact in the appropriate section:

How to Populate Custom Fields on Convert

Create a Copy of /modules/Leads/views/view.convertlead.php in
custom/modules/Leads/views/ …

Edit you copy in /custom directly

Insert your code from here ( i.e line 460 ) put something like this
Below you can use mapping against standard modules, to custom lead fields as follows:

// Insert your code from here ( i.e line 460 ) put something like this
     // Below you can use mapping against standard modules, to custom lead fields as follows
       if ($module == 'Accounts')
        {
      // Here I Map custom wfs_industry_c ( a dropdown field, which uses industry_dom, as does Accounts )
      // These mappings operate in the background, so you will not see these fields in the Convert UI
      // Also NOTE: This modification is not necessary if your Account field and Lead field have the identical name,
      // as that is taken care of automatically.
      // See also
      $beans[$module]->industry = $lead->wfs_industry_c;
         }

so your logic would be something like: $lastname = $lead -> lastaname
if $lead->lastname = "N/D" then $lastname = "null"

$beans[$module] -> lastname = $lastname

1 Like

I’ve mapped the field for convertion in the file /modules/Leads/views/view.convertlead.php; then I’ve copied it in custom/modules/Leads/views/ and then I’ve added the following code from line 463 but nothing changed

if ($beans['Contacts']->last_name == "N/D") {
    $beans['Contacts']->last_name = NULL;
}

The last_name field has “N/D” value

The exsmple was for accounts. Its not exactly at line 463 you have you add it in the part that deals with the contact creation. Also you have you repair and rebuild before changes will take effect. Also i think you want lead last name not contact last name equals n/d then updates the contact.

I also tried to replace the code in the previous message with:

if ($lead->last_name == "N/D") {
    $beans['Contacts']->last_name = "";
}

Nothing changed!!!

I have had repair and rebuild.

What I need is explained in the previous messages. I don’t need an example about something different.