Get/create related bean link (href)

Hey there,

I’ve managed to display related fields on a custom module with load_relationship(). -> Display contact name for example.

Everything work great I can display thoses fields, but thoses fields are related fields. And I need to make a link to the module.

For example make a href link for the contact.

I’ve saw this thread wich can work :

But If I want to make it work I need the related bean ID. And I dont know how to get it since thoses are related fields…

Hope someone have the same need has me…

Have a great week end everyone !

Is this a List view, a detail view, or another thing?

For example this technique might help out

you can use any PHP, including navigating relationships, to get to your data, and then build the HTML.

Hey there,

This is for the detailview mate !

I want to make a link like a normal realtionships.

For now I success in displaying the fields, but not in making it a link… I need the ID of the module related

Tried something like that… But it doesnt work :

$coopBeans = $this->bean->coop_cooperative_opportunities_1->getBeans();
$test = $coopBean->coop_cooperative_coop_cooperative_1_name;    
   --> This display great the name I want ! But ofc without a link ...

Now I want to access the bean to get the ID and build a link but dont rly know how to do it … :

print_r('bean : '.$test->bean);

The end of the idea is to make something like this in a href :$MY_ID_VAR

For detail views, try starting from this example:

Hey man,

Thanks for the support again.

Looked the code and it dont really fit my need, for now Im trying to retreive the bean with the string value, looking on internet for this …

Sry I cant edit my last post dont know why …

Trying to get the ID with the function retrieve_by_string_fields() wich I’ve found in the documentation

It retrieve me a Object of class coop_Cooperative (cooperative is my module !)

Dont rly know what to do with it … Cant convert it to bean …

The bean is right there in


and then you can use load_relationship to get the related beans.

Thats what I use.

But I need the ID of the related bean.

Here is a part of my code :

$compte_link = 'accounts_opportunities_2';

        if( $this->bean->load_relationship( $compte_link ) ) 
            $organisationBeans = $this->bean->$compte_link->getBeans();
            $organisationBean = reset($organisationBeans);
			//Ajout du parrain
            $this->ss->assign( 'ParrainBeneficiaire', $organisationBean->contacts_accounts_1_name );

I need the ID of "contacts_accounts_1_name "

Like $organisationBean->contacts_accounts_1_name->get()

But its a string so Im trying to use retrieve_by_string_fields()

Okay I make it workkkkkkkk

For thoses who want to do it here is the full code :

In my view.detail.php :

$coop_link = 'coop_cooperative_opportunities_1'; 
		if( $this->bean->load_relationship( $coop_link ) ) 

			$coopBeans = $this->bean->$coop_link->getBeans();
			$coopBean = reset($coopBeans);
			//Try d'avoir l'ID pour link
			$BeanCoopérative = $accountBean = BeanFactory::getBean('coop_Cooperative');
			$CoopParentBean = $BeanCoopérative->retrieve_by_string_fields
                                  'name' => $coopBean->coop_cooperative_coop_cooperative_1_name
							// $encode=true
			print_r('bean : '.$CoopParentBean->id);
			//Ajout de la coopérative parent
            $this->ss->assign( 'ParentCoop', $coopBean->coop_cooperative_coop_cooperative_1_name );
			//Ajout de l'ID coopérative parent
            $this->ss->assign( 'IDParentCoop', $CoopParentBean->id );

In my detailviewdef.php :

array (
            'name' => 'LBL_ParentCoop',
            'customCode' => '<a href="{$IDParentCoop}" target="_blank" >
			'label' => 'Coopérative Parent',

It work, really dont know if its the good way to do it cause it create a field just for the ID… Cant know if with all my database It will work great … If a pro can tell me if its the good way to do it or not.

1 Like