AnsweredAssumed Answered

How to get value from parent module (one to many) with Logic Hook?

Question asked by Arpad Szabo on Aug 22, 2016
Latest reply on Sep 12, 2016 by sidhu sidhu

Hello!

 

I building a new, unique ID for a custom contract module. 

The contract module is in a One to Many realtionship with Account module, so one Contract only belongs to one Account. 

In Contracts module I have to get the name of the related Account via before save LogicHook. 

Here is the code i used. All the parts are working but I cant get value for the $ID_RelAccount variable: 

 

When I save a new record I must get the following format ID: "SZ_COON_20160822_114257"

I cant get the "red" COON value which is generated via match from a list and the related Account name (if they match)

 

<?php
//Place here: custom/modules/Contracts/
//(ver1)
class GenerateID {
function GenerateID_SZ($bean, $event, $arguments)
{
// This "if" statement makes sure that the record only runs when a new record is first created.
//Without the "if" statement, tbe ID will be regenerated everytime the record is edited.
if ($bean->name == '0')
{

$ID_companyDB = array( //This is a list of acceptable Account names and format keys.
COON => 'Company One LLC.',
COTW => 'Company Two LLC.',
COTH => 'Company Trhee LLC.');

//Getting nothing from related Account with the following code
$ID_RelAccount = BeanFactory::getBean("Accounts",$name);
if($ID_RelAccount->load_relationship('accounts_contracts'))

{
$relatedBeans = $ID_RelAccount->accounts_contracts->getBeans();
return $relatedBeans;
}

 

$companycode = array_search($ID_RelAccount,$companyDB); //Search: are $ID_RelAccount is in list?
$date = new DateTime(); //new date variable
$ID_uniquedate = $date->format('Ymd_His');//Getting the special format datetime as unique number.

 

$ID_code = "SZ_{$ID_companycode}_{$ID_uniquedate}";//Concatenate the values of the variables

 

$bean ->name = $ID_code;//Giving back the unique identifyer to tha name field.
}
}
}
?>

 

Thank You, 

Arpad

Outcomes