Hi @oAnbin
I think that the Documents-Opportunities is a many to many relationship, right? Or do you have any custom changes to the relationship?
Relationship definition from documents_opportunitiesMetaData.php
$dictionary["documents_opportunities"] = array(
'true_relationship_type' => 'many-to-many',
'relationships' =>
array(
'documents_opportunities' =>
array(
'lhs_module' => 'Documents',
'lhs_table' => 'documents',
'lhs_key' => 'id',
'rhs_module' => 'Opportunities',
'rhs_table' => 'opportunities',
'rhs_key' => 'id',
'relationship_type' => 'many-to-many',
'join_table' => 'documents_opportunities',
'join_key_lhs' => 'document_id',
'join_key_rhs' => 'opportunity_id',
),
),
'table' => 'documents_opportunities',
For many to many relationships you need to use the set_relationship
from the V4 API.
V4 API set_relationship details from /service/v4_1/rest.php
/**
* Set a single relationship between two beans. The items are related by module name and id.
*
* @param String $session -- Session ID returned by a previous call to login.
* @param String $module_name -- name of the module that the primary record is from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
* @param String $module_id - The ID of the bean in the specified module_name
* @param String link_field_name -- name of the link field which relates to the other module for which the relationship needs to be generated.
* @param array related_ids -- array of related record ids for which relationships needs to be generated
* @param array $name_value_list -- The keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
* @param integer $delete -- Optional, if the value 0 or nothing is passed then it will add the relationship for related_ids and if 1 is passed, it will delete this relationship for related_ids
* @return Array - created - integer - How many relationships has been created
* - failed - integer - How many relationsip creation failed
* - deleted - integer - How many relationships were deleted
* @exception 'SoapFault' -- The SOAP error, if any
*/
Method [ public method set_relationship ] {
- Parameters [7] {
Parameter #0 [ $session ]
Parameter #1 [ $module_name ]
Parameter #2 [ $module_id ]
Parameter #3 [ $link_field_name ]
Parameter #4 [ $related_ids ]
Parameter #5 [ $name_value_list ]
Parameter #6 [ $delete ]
}
}
So, to add the relationship you need to do something like:
$parameters = [
'session' => $session_id,
'module_name' => 'Documents',
'id' => $document_id,
'link_field_name' => 'opportunities',
'relate_ids' => [$idOportunidad],
'name_value_list' => [],
'delete' => 0
];
$set_entry_result_document = call("set_relationship", $parameters, $url);
Hope this helps