AnsweredAssumed Answered

How to filter through records using bean factory

Question asked by David Matrai on Feb 13, 2019
Latest reply on Feb 13, 2019 by David Matrai

Hello Sugar Developer Community 

 

I am having difficulties accomplishing the following 

-- Entrypoint ::  create leads 

 

JSON is sent over and the creation of the lead is underway 

 

 

I am passed a value that would represent a company name to place into a company name relate field. 

 

Problem: 

Cannot add relate without the ID 

-- Trying to get the ID by name 

$sql = new SugarQuery();
$accBean = BeanFactory::getBean("Accounts");
$sql->select('id');
$sql->from($accBean);
$nameAC = $vars->architectComp;     *** is an account name
$sql->where()->contains('name', $nameAC);
$result = $sql->execute();
$bean->account_id_c = $result[0]['id'];      //When replaced with an existing ID string . -- write successful 

 

I always get an empty result .     -- from what i gather my $accBean is empty because i have supplied no ID 

 

Please help me understand how to load the accounts and itereate through them to get an ID if the name is a match. 

** Would like to use the current recommended sugar standards as of 8.0 but if it has to be "hacky" i can work with that !

 

Thank you 

Outcomes