How to get all cases linke to Opportunity?

I try to get all cases, linke to an opportunity (for example).

I need the information in a LogicHook because i want to link the same cases to another type (in this specific case to a document).

I´ve tried a lot, but always unable to fetch the linked Cases.

Fullscreen
1
2
3
4
5
6
7
$cases1 = $opportunity->get_linked_beans('opportunities_cases_1', 'aCase');
$cases2 = $opportunity->get_linked_beans('opportunities_cases', 'aCase');
if ($opportunity->load_relationship('cases')){
$caseBeans = $opportunity->cases->getBeans();
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In this example - $case1 and $case2 is "0" and $caseBeans never reached.

What´s the best or correct way to determine all attached/linke cases to a bean?

Appreciate any help. Thanks a lot.

Parents
  • get_linked_beans is how we used to do it years ago in version 6, but that method has been obsolete for quite some time.

    The way to get related beans is what  described, just make sure that your link name ($relationship, in Jeroen's code) is correct. Although I'm not familiar with the use of AcuityLog and I suspect it's an add-on to his particular setup.

    What version of Sugar are you working with?

    FrancescaS

  • It´s - now - Sugar 10 we have in use. With quite old custom code.

    Jeroens Code helped me a lot and it work´s now like a charm.

    Currently i only struggle again to add to documents a new relationship to existing cases. you haven´t a helper too? ;-)

Reply Children
  • To relate the child record to the bean:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    $relationship = 'my_relationship' //the relationship link name as above;
    $child_record_id = '123' //the id of your child record;
    //$bean is the parent bean
    if($bean->load_relationship($relationship) && !empty $child_record_id)){
    $bean->$relationship->add($child_record_id);
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    You may want additional check to make sure your child's record ID exists etc...