Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a relationship between Leads and Custom Modules in SugarCRM CE?

function createPJOpportunityRelationship($pj_id, $op_id) {
    echo "creating relationship";

    $set_relationship_value = array(
        'module1' => 'geral_pessoa_juridica', 'module1_id' => $pj_id,
        'module2' => 'Opportunities', 'module2_id' => $op_id
    );

    $set_relationship_params = array(
        'session' => $this->ses,
        'set_relationship_value' => $set_relationship_value
    );

    $set_relationship_result = $this->soap->call('set_relationship', array(
        'session' => $this->ses,
        'set_relationship_value' => $set_relationship_value));

    var_dump($set_relationship_result);
}

This is the code I'm using to create a relationship, according to most sugar tutorials. The code works when I'm using 2 basic modules (Like Leads/Contacts) but it fails when I try it with custom built modules.

In this case, the geral_pessoa_juridica module is a custom one, geral being the package and pessoa_juridica the name. I'm sure the name is correct, it works for other functions.

This function returns to me this

5ec9ca75-e09d-e2d8-0c2b-4df7ac377dcf creating relationship array(3) { ["created"]=> int(0) ["failed"]=> int(1) ["deleted"]=> int(0) }

I'm not sure WHY it fails - studying sugarcrm.log, I see it didn't even tried to create the relationship.

I remade the module twice, tried to create the tables manually following the Sugar standard I saw in other relationships, flushed MySQL privileges, did all the repairs possible in Sugar. I can't reinstall it because it's on production.

Any ideas on how to fix it?

like image 577
Lucas Famelli Avatar asked Jun 14 '11 20:06

Lucas Famelli


2 Answers

There's an error on line 5:

'module1' => 'geral_pessoa_juridica', 'module1_id', $pj_id,

should instead be:

'module1' => 'geral_pessoa_juridica', 'module1_id' => $pj_id,
like image 119
Kåre Werner Storgaard Avatar answered Sep 29 '22 09:09

Kåre Werner Storgaard


Solved, or kinda of.

    $set_relationship_params = array(
        'session' => $this->ses,
        'module_name' => 'custom_module', /* custom module, where the relationship was created, "primary module" */
        'module_id' => $custom_id, /* id of site, get from set_entry call */
        'link_field_name' => 'module', /* the LINK field type name, from Step 5  */
        'related_ids' => array($module_id) /* id of Account you want to relate to */
    );

    print_r($result = $this->soap->call('set_relationship',$set_relationship_params)); //nuSoap
}
like image 27
Lucas Famelli Avatar answered Sep 29 '22 11:09

Lucas Famelli