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 sa开发者_开发问答w 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?
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,
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
}
精彩评论