Hello
When we converted lead to contact, accounts, opportunity
records we also have taken those created ID in database lead table in contact_id account_id, opportunity_id
Also, we have a new record in WorkFlow as contact id, account id, opportunity id
so we can easily detect and do workflow process…
So I wanna add a new Custom module to this process I wrote above
I investigate how it is working right now for standard modules Contacts, Accounts, Opportunity and trying to add my custom module like copy paste…
What I did:
-
for appear my custom module in workflow list go to
modules/Leads/vardefs.php
and'people_id' => array( 'name' => 'people_id', 'type' => 'id', 'reportable' => false, 'vname' => 'LBL_PEOPLE_ID', 'comment' => 'If converted, people ID resulting from the conversion' ), 'people' => array( 'name' => 'people', 'type' => 'link', 'link_type' => 'one', 'relationship' => 'people_leads', 'source' => 'non-db', 'vname' => 'LBL_PEOPLE', 'reportable' => false, ),
The result looks like
-
for appear my custom module in convert list go to
modules/Leads/metadata/convertdefs.php
and add records of my custom module$viewdefs['people']['ConvertLead'] = array( 'copyData' => true, 'required' => false, 'templateMeta' => array( 'form'=>array( 'hidden'=>array( ) ), 'maxColumns' => '2', 'widths' => array( array('label' => '10', 'field' => '30'), array('label' => '10', 'field' => '30'), ), ), 'panels' =>array( 'LNK_NEW_PEOPLE' => array( array( 'name', ), array( 'description' ), ) ), );
ok, right now I can create a new record in my custom module BUT it’s not written ID of created a new record anywhere so the next step
- Go to
modules/Leads/Lead.php
and define
public $people_id;
public $people_name;
then I found get_contact(account, opportunity) functions and make another one with my custom module name (and adding logger to see in logs if it’s return anything)
public function get_people()
{
if (isset($this->people_id) && !empty($this->people_id)) {
$query = "SELECT name, assigned_user_id people_name_owner FROM people WHERE id='{$this->people_id}'";
$GLOBALS['log']->fatal('People ID in get_people(global): ', $this->people_id, $people_id );
LoggerManager::getLogger()->fatal('People ID in get_people(logger): ', $this->people_id);
//requireSingleResult has beeen deprecated.
//$result = $this->db->requireSingleResult($query);
$result = $this->db->limitQuery($query, 0, 1, true, "Want only a single row");
if (!empty($result)) {
$row = $this->db->fetchByAssoc($result);
if (!is_null($row) && !is_bool($row)) {
$this->people_name = $row['name'];
$this->people_name_owner = $row['people_name_owner'];
} else {
$this->people_name = null;
$this->people_name_owner = null;
}
$this->people_name_mod = 'People';
}
}
}
also, there is Convert_lead function where I just add $peopleid
public function converted_lead($leadid, $contactid, $accountid, $opportunityid, $peopleid)
{
$query = "UPDATE leads set converted='1', contact_id=$contactid, account_id=$accountid, opportunity_id=$opportunityid, people_id=$peopleid where id=$leadid and deleted=0";
$this->db->query($query, true, "Error converting lead: ");
//we must move the status out here in order to be able to capture workflow conditions
$leadid = str_replace("'", "", $leadid);
$lead = BeanFactory::newBean('Leads');
$lead->retrieve($leadid);
$lead->status='Converted';
$lead->save();
$GLOBALS['log']->fatal('People ID in converted_lead(global): ',$contactid, $peopleid);
LoggerManager::getLogger()->fatal('People ID in converted_lead(logger): ',$contactid, $peopleid);
}
It’s all that I found relate to $contactid, $accountid, $opportunityid
My current result when I did test converting was - creating a new my custom module record BUT it’s still not writing created record ID in database Lead
As you can see on the screenshot it sees, like writing in people_id just empty value (overwrite NULL)
the logger also shows me a empty value.
What could I be missing?
how can I display the ID of the created record and write it to the database