2017-06-16 11 views
1

保存ボタンをクリックしてページをリダイレクトする直前に、javascriptを使用して新しく作成したレコードのIDを取得したいと思います。ページをリダイレクトする前に新しく作成したIDを取得する

あなたがどんな考えをしてください持っていますか?

ありがとうございました!

+0

これは、サーバに非同期メッセージを送信するレコードを作成し、レコードIDで応答が必要です。 Ajaxを見て、クライアント側で成功/失敗を処理する。 – btl

+0

特に何シュガー/ SuiteCRMのバージョンとは、特定のどのモジュール(すべてではない場合)、あなたはこれがために必要なのですか? – Jay

+1

私はあなたの情報のために、私はどんなにsuitecrmのバージョンシュガー6.5を使用しています、(後の保存)ロジックフックを使用してこれを解決しました。 ありがとうございます! – Hachim

答えて

-1

私は、ロジックフックを使用してこれを解決:あなたが拡張ビューにさらにいくつかの読書をしたい場合は

はまた、このトピックについてSugarCRM社のdevのブログ投稿があり私はsuitecrmのバージョンに関係なくSugar 6.5を使用しています。

ありがとうございました!

0

Sugar 7でこれを行う1つの方法は、CreateViewをオーバーライドすることです。

新しいアカウントが正常に作成された後、Sugarが作成されたレコードに反応する前に、alert-messageに新しいIDを出力するCustomCreateViewの例を示します。

custom/modules/Accounts/clients/base/views/create/create.js

({ 
    extendsFrom: 'CreateView', 

    // This initialize function override does nothing except log to console, 
    // so that you can see that your custom view has been loaded. 
    // You can remove this function entirely. Sugar will default to CreateView's initialize then. 
    initialize: function(options) { 
     this._super('initialize', [options]); 
     console.log('Custom create view initialized.'); 
    }, 

    // saveModel is the function used to save the new record, let's override it. 
    // Parameters 'success' and 'error' are functions/callbacks. 
    // (based on clients/base/views/create/create.js) 
    saveModel: function(success, error) { 

     // Let's inject our own code into the success callback. 
     var custom_success = function() { 
       // Execute our custom code and forward all callback arguments, in case you want to use them. 
       this.customCodeOnCreate(arguments) 
       // Execute the original callback (which will show the message and redirect etc.) 
       success(arguments); 
     }; 

     // Make sure that the "this" variable will be set to _this_ view when our custom function is called via callback. 
     custom_success = _.bind(custom_success , this); 

     // Let's call the original saveModel with our custom callback. 
     this._super('saveModel', [custom_success, error]); 
    }, 

    // our custom code 
    customCodeOnCreate: function() { 
     console.log('customCodeOnCreate() called with these arguments:', arguments); 
     // Retrieve the id of the model. 
     var new_id = this.model.get('id'); 
     // do something with id 
     if (!_.isEmpty(new_id)) { 
      alert('new id: ' + new_id); 
     } 
    } 
}) 

私はシュガー7.7.2.1のアカウントモジュールでこれをテストしたが、砂糖内の他のすべてのサイドカーモジュールのためにこれを実装することが可能でなければなりません。 しかし、このモジュールの意志ない作業BACKワットC OMPATIBILITYモード(そのURLに#bwc有するもの)ard-。

注:問題のモジュールがすでにBase<ModuleName>CreateView独自のを持っている場合、あなたはおそらく<ModuleName>CreateViewから延びる(なしBase)の代わりに、デフォルトCreateViewからすべきです。

このコードは、Sugarのアップグレード中に壊れる可能性が低いことにご注意ください。デフォルトCreateViewコードはsaveModel関数定義の変更を受信した場合。 、あなたの情報のため、(後の保存)https://developer.sugarcrm.com/2014/05/28/extending-view-javascript-in-sugarcrm-7/

関連する問題