SugarCRM: How to get list of all documents related to an account
A few days ago I responded to a question on stackoverflow.com which posed the question of how to get through the web services exposed by SugarCRM list of documents relating to a particular account.
Among the operations that are available as web services that takes the name of get_relationships is the one that answers the question asked. The support portal is available extensive documentation of this operation, in addition, this operation is accessible via REST and SOAP away. The operation get_relationships retrieves the data of a specific relationship for a specific record.
The examples section of the documentation get_relationships shows an example of use, just make adjustments alone operation input parameters for our case of interest. In Listing 1 shows the array of input parameters to retrieve documents related to the account and Listing 2 shows the result.
On my public repository is available at https://gist.github.com/amusarra/6436845 the complete example of the call to REST service get_relationships. The same applies to the call to the service using SOAP. Regarding the interaction with SOAP services SugarCRM, there are a variety of sources, some of which are available on my blog and slideshare:
- Building a Client .NET for SugarCRM
- Costruire un client Java per SugarCRM
- Alloy UI Autocomplete: Get data from SugarCRM
The SugarCRM REST services will gradually replacing SOAP services, they were a bit backwards in terms of the most recent standards.
$session_id, //The name of the module from which to retrieve records. 'module_name' => 'Accounts', //The ID of the specified module bean. 'module_id' => '13111fcd-1884-2a71-0b37-50b7d0f188f6', //The relationship name of the linked field from which to return records. 'link_field_name' => 'documents', //The portion of the WHERE clause from the SQL statement used to find the related items. 'related_module_query' => '', //The related fields to be returned. 'related_fields' => array( 'id', 'name', ), //For every related bean returned, specify link field names to field information. 'related_module_link_name_to_fields_array' => array( ), //To exclude deleted records 'deleted'=> '0', //order by 'order_by' => '', //offset 'offset' => 0, //limit 'limit' => 5, ); $get_relationships_result = call("get_relationships", $get_relationships_parameters, $url); ?>
Listing 1. Input parameters to retrieve documents related to the account
stdClass Object ( [entry_list] => Array ( [0] => stdClass Object ( [id] => 8b4c0450-1922-498f-4601-52272fa6e494 [module_name] => Documents [name_value_list] => stdClass Object ( [id] => stdClass Object ( [name] => id [value] => 8b4c0450-1922-498f-4601-52272fa6e494 ) [name] => stdClass Object ( [name] => name [value] => WebProxyService_A.png ) ) ) ) [relationship_list] => Array ( ) )
Listing 2. Result returned by the operation get_relationships.