Sugarcrm:如何使用Rest v4从自定义模块中检索相关记录?

时间:2013-10-01 13:35:47

标签: sugarcrm

在全新安装的Sugarcrm 6.5 CE上,我创建了一个自定义模块“Groupes”,与帐户有多对多的关系。

我在“帐户”中添加了一条记录,在“Groupes”中添加了一条记录,并将它们链接在一起。

我的目标是使用REST v4检索“Groupes”中的记录以及相关的帐户记录。

使用get_entry_list,我尝试了以下内容:

//retrieve records ----------------------------------------

$get_entry_list_parameters = array(

     //session id
     'session' => $session_id,

     //The name of the module from which to retrieve records
     'module_name' => "Accounts",

     //The SQL WHERE clause without the word "where".
     'query' => "",

     //The SQL ORDER BY clause without the phrase "order by".
     'order_by' => "",

     //The record offset from which to start.
     'offset' => "0",

     //Optional. The list of fields to be returned in the results
     'select_fields' => array(
          'id',
          'name',
     ),

     //A list of link names and the fields to be returned for each link name
     'link_name_to_fields_array' => array(
          array(
               'name' => 'offi1_groupes',
               'value' => array(
                    'id',
                    'name',
               ),
          ),
     ),

     //The maximum number of results to return.
     'max_results' => '10000',

     //To exclude deleted records
     'deleted' => 0,

     //If only records marked as favorites should be returned.
     'Favorites' => false,

);

$get_entry_list_result = call("get_entry_list", $get_entry_list_parameters, $url);

下面你可以看到我得到的结果:正如你所看到的,“Groupes”记录未被提取。对于出了什么问题的任何线索?

stdClass Object
(
[result_count] => 1
[total_count] => 1
[next_offset] => 1
[entry_list] => Array
    (
        [0] => stdClass Object
            (
                [id] => 671d043b-7c39-e2b8-66ee-5249d0d8c954
                [module_name] => Accounts
                [name_value_list] => stdClass Object
                    (
                        [id] => stdClass Object
                            (
                                [name] => id
                                [value] => 671d043b-7c39-e2b8-66ee-5249d0d8c954
                            )

                        [name] => stdClass Object
                            (
                                [name] => name
                                [value] => Pharmacie témoin
                            )

                    )

            )

    )

[relationship_list] => Array
    (
        [0] => stdClass Object
            (
                [link_list] => Array
                    (
                        [0] => stdClass Object
                            (
                                [name] => offi1_groupes
                                [records] => Array
                                    (
                                    )

                            )

                    )

            )

    )

)

image

1 个答案:

答案 0 :(得分:1)

首先获取帐户ID

self::$soap->get_entry_list(self::$sessionId, 'Accounts', "name='NAME'");
$acc_id = $response->entry_list[0]->id;

从关系中获取群组ID

$get_relationships_result = self::$soap->get_relationships(self::$sessionId,"Accounts",$acc_id,"Groupes");
$groups_id = $get_relationships_result->ids[0]->id;

返回并获取相关组信息

self::$soap->get_entry_list(self::$sessionId, 'Groupes', "Groupes.id=$groupes_id");