AnsweredAssumed Answered

Using SugarBeanApiHelper with relationships

Question asked by john Fieldsend on Feb 8, 2020
Latest reply on Feb 8, 2020 by john Fieldsend

Can someone offer advice our point me to some documentation

 

Im trying to retrieve a contact and there related account details, I dont want to retreive everything as I only need selected fields and also want to reduce overheads. I can get this doing an sql request but wanted to understand more how to do things with beanFactory

 

I have the following

        $contactBean = BeanFactory::retrieveBean('Contacts', $args['ID']);

        if ($contactBean) {
            if ($contactBean->load_relationship('accounts')) {
               $accountBean = $contactBean->accounts->getBeans();
            }

            $helper = new SugarBeanApiHelper($api);
            $result['success'] = true;
            $result['records'] = $helper->formatForApi($contactBean, array('id', 'name', 'portaluser_c'));
            return $result;
        }

        $result['errors'] = "Contact details not found.";
        return $result;

The relationship is working but Im stuck on how i then include the accounts details i want with $helper->formatForApi

 

Do i need to crate a new bean for the account? or am i going about this the wrong way?

Outcomes