AnsweredAssumed Answered

custom massupdate action in list view

Question asked by Francesca Shiekh on Mar 7, 2015
Latest reply on Mar 7, 2015 by Francesca Shiekh
I am having trouble understanding how to make out-of-the-box API calls with parameters from a js script. 

I defined an action in custom/modules/clients/base/views/recordlist/recordlist.php
which should mass update the selected records in Cases List View with some given values.
               
      array (
        'name' => 'close_as_spam',
        'type'=>'button',
        'label' => 'LBL_CLOSE_AS_SPAM_ACTION',
        'acl_action' => 'edit',
        'primary'=> true,
        'events' => array(
          'click' => 'list:closeasspam:fire',
        ),
      ),
                 

and created a custom/modules/clients/base/views/recordlist/recordlist.js to handle the event


({
   extendsFrom: 'RecordlistView',
   initialize: function(options){
      console.log('RecordListView');
      this._super('initialize', [options]);
      this.context.on('list:closeasspam:fire', this.closeAsSpamClicked, this);
      this.context.on('list:closeastraining:fire', this.closeAsTrainingClicked, this);
      this.context.on('list:closeconfirmed:fire', this.closeConfirmedClicked, this);
      this.context.on('list:closequick:fire', this.closeQuickClicked, this);
   },
   updateRecords: function(params){
     var url = app.api.buildURL(this.module, "MassUpdate");
     app.api.call('PUT',url,params,{
       success: function(o){
         console.log('done');
         console.log(o);
       },
       error: function(e){
         console.log(e);
       },
     });
   },
   closeAsSpamClicked : function() {
     console.log('closeAsSpamClicked');
     var ids = _.map(this.context.get('mass_collection').models, function(selected_model){return selected_model.id}),
         params = {massupdate_params:{
           uid:ids,
           status:"Closed",
           resolution:"Closed as Spam",
           case_closed_reason_c:"Spam"
         }};
     this.updateRecords(params);
   },
                                                                                   


I separated the closeAsSpamClicked from the updateRecords because I want to reuse updateRecords for other custom buttons with different status/resolution etc.


When I try to use this I get an error in the console:

GET https://<myserver>/sugarcrm/rest/v10/Cases/MassUpdate 404 (Not Found)  
SUGAR.Api.s {request: SUGAR.Api.o, status: 404, responseText: "{"error":"not_found","error_message":"Could not find record: MassUpdate in module: Cases"}", textStatus: "error", errorThrown: "Not Found"...}

It iseems to call GET /<module>/:record 

rather than PUT /<module>/MassUpdate

And I'm clearly not understanding how to call an API and pass parameters to it....

or maybe it's just Friday :)

Any clues welcome, thanks.

FrancescaS

Outcomes