2016-12-07 13 views
0

追加のアクションをレコードリストビューに追加しました。SugarCRM:RESTエンドポイントでjsonデータを取得する方法

custom/modules/Opportunities/clients/base/views/recordlist/recordlist.js:

({ 
    extendsFrom: 'RecordlistView', 

    initialize: function(options) { 
     this._super("initialize", [options]); 
     //add listener for custom button 
     this.context.on('list:opportunitiesexport2:fire', this.export2, this); 
    }, 
    export2: function() { 
     //gets an array of ids of all selected opportunities 
     var selected = this.context.get("mass_collection").pluck('id'); 
     if (selected) { 
      return App.api.call('read', 
      App.api.buildURL('Opportunities/Export2'), 
      {'selected_ids':selected}, 
      { 
       success: function(response) { 
        console.log("SUCCESS"); 
        console.log(response); 
       }, 
       error: function(response) { 
        console.log('ERROR'); 
        console.log(response); 
       }, 
       complete: function(response){ 
        console.log("COMPLETE"); 
        console.log(response); 
       }, 
       error: function(response){ 
        console.log("ERROR"); 
        console.log(response); 
       } 
      }); 
     } 
    }, 
}) 

ここでチュートリアル http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Integration/Web_Services/v10/Extending_Endpoints/ は、エンドポイントを作成する方法について説明します。

しかし、jsonデータ(選択されたIDの文字列化された配列)の取得方法は説明されていません。

custom/modules/Opportunities/clients/base/api/OpportunitiesApi.php:

class OpportunitiesApi extends SugarApi 
{ 
    public function registerApiRest() 
    { 
     return array(
      //GET 
      'MyGetEndpoint' => array(
       //request type 
       'reqType' => 'GET', 

       //set authentication 
       'noLoginRequired' => false, 

       //endpoint path 
       'path' => array('Opportunities', 'Export2'), 

       //endpoint variables 
       'pathVars' => array('', ''), 

       //method to call 
       'method' => 'Export2', 

       //short help string to be displayed in the help documentation 
       'shortHelp' => 'Export', 

       //long help to be displayed in the help documentation 
       'longHelp' => 'custom/clients/base/api/help/MyEndPoint_MyGetEndPoint_help.html', 
      ), 
     ); 
    } 

    /** 
    * Method to be used for my MyEndpoint/GetExample endpoint 
    */ 
    public function Export2($api, $args) 
    { 
     //how to access $args['selected_ids']? 
    } 
} 

$args

Array 
(
    [__sugar_url] => v10/Opportunities/Export2 
) 

が含まれているJSONデータにアクセスすることが可能ですか?

答えて

0

解決方法は、コール方法をcreateに変更し、エンドポイント方法をPOSTに変更することでした。私は何も変更する予定はありませんでしたので、私はGETを使用していたが、体は通常のGETリクエストでは無視される - $argsは今

Array 
(
    [selected_ids] => Array 
     (
      [0] => 0124a524-accc-11e6-96a8-005056897bc3 
     ) 

    [__sugar_url] => v10/Opportunities/Export2 
) 

PUT vs POST in RESTが含まれています。

0

私は同じことをしましたが、私の残りのAPIはjavaでコード化されていました。私はgetメソッドをアノテートするためにjava @Pathアノテーションを使用しました。私はサーバーの上に残りのAPIコードを配置しました(私の場合はTomcat)。サーバーを起動し、@Pathで形成されたURLを押すと、ブラウザー上のjsonデータが得られます。

関連する問題