open selection-list with predefined collection no longer works in 7.7.x

In 7.6.x I can open a selection-list drawer with a collection built from a customAPI call.

      url = app.api.buildURL(<mycustomAPIhere>);
      app.api.call('GET', url, null, {
        success:function(data){
          contacts = app.data.createBeanCollection("Contacts",data['records']);
          app.drawer.open({
            layout: 'selection-list',
            context: {
               module: linkModule,
               parentModel: parentModel,
               collection:contacts,
               filterOptions:{
                 stickiness:false,
                 auto_apply:false,
               },
            }
          }, function(selectedModel) {
               if (!_.isEmpty(selectedModel)) {
                  self.model.set('contact_id_c', selectedModel.id);
                  self.model.set('point_of_contact_c', selectedModel.name);
               }
          });//app drawer
        },
        error:function(e){
          console.log(e);
        },
      });//api
    }
  },

in 7.7 this no longer works, it looks like the collection is no longer an option in the selection-list

I get a very funky non-drawer opening with just the select radio buttons on the left and some list headers on the right hand side.. it looks like the center of the drawer is not drawn or hidden behind the other drawer...

Interestingly if I set skipFetch = false in the selection-list context it does return rows, albeit hidden by the prior drawer

          app.drawer.open({
            layout: 'selection-list',
            context: {
               module: linkModule,
               collection: contacts,
               skipFetch: false,
            }

and  if I select one of the radio buttons in the Select Column, it does return the record and populate the point_of_contact_c as desired.

It's as if it's not drawing the actual list though the contents are there...

Any thoughts on opening a selection-list with a pre-defined collection in 7.7?

Thanks,
FrancescaS

NOTE:

filter_relate is great when everything is based off relate fields but does not work on relationships.

Parents
  • Fixed. Requires model passes explicitly.

              app.drawer.open({
                layout: 'selection-list',
                context: {
                   module: linkModule,
                   model: linkModel,
                   parentModel: parentModel,
                   collection:addresses,
                   filterOptions:{
                     stickiness:false,
                     auto_apply:false,
                   },
                }
  • Hello Francesca Shiekh, Kenneth Brill,

    I'm not able either to make this work. As Kenneth Brill, I don't know how to get the linkModel parameter, and also what to put in the parentModel one. I also get the this.createLinkModel is not a function error.

    I think this can be very powerful, if anyone knows how to use it!

    Thank you.

    Regards,

    David.

    sidhu sidhu, Matt Marum, Angel Magana

  • David López, Kenneth Brill

    Sorry Kenneth, I just saw this, I must have missed your question.

    In my example:

              

              parentModel = this.model, //the model I'm on in my custom module.

              linkModule = 'Contacts'; //the model for which I created the collection and whose drawer I want to open

              linkModel = app.data.createBean(linkModule); //the bean for the related module 

    HTH,

    FrancescaS

  • Thanks for that Francesca Shiekh.

    Right now I can open my drawer with the selection-list layout in this way:

    I add the plugin 'LinkedModel' in the initialize function:

    initialize: function(options) {
            this.plugins = _.union(this.plugins, ['LinkedModel']);
            this._super('initialize', [options]);
        }

    What I'm trying to achieve is to make an api call to the global search engine endpoint with the specified query, and then show these results as a list in the selection-list drawer.

    The search function that opens my drawer:

    search: function(query) {
        var self = this;
        var model = self.model;
        app.api.call( 'get', app.api.buildURL('ProductTemplates/globalsearch?q=' + query), null, {
            success: function(res) {
                if(res && res.records) {
                    var pt = app.data.createBeanCollection("ProductTemplates", res.records);
                    app.drawer.open({
                        layout: 'selection-list',
                        context: {
                            module: "ProductTemplates",
                            parent: self.context,
                            model: self.createLinkModel(model, 'revenuelineitem_templates'),
                            collection: pt,
                            filterOptions:{
                                auto_apply:false,
                            }
                        }
                    }, _.bind( self.setProductFromSearchSelection, { model: model }));
                }

            },
            error: function(err) {

            }
        });

    }

    This way, the drawer opens and I see the list with the retrieved beans from the query. However, I have got two problems:

    1. Not all the columns in the selection-list layout are filled out, only a few. For instance, the name is filled, but some columns with custom fields are not filled (if I press the "Preview" button, then columns are filled out with the apppropiate values.
    2. In the bottom of the list, the "Show more" button that should appear if we've got more rows than the specified limit of rows per page does not appear and instead I've got a "Loading..." message all the time, so I can't show more pages.

    Have you also faced these issues? Or does anyone know how to solve them?

    Thank you very much.

    Regards,

    David.

  • Hello David López I have not tried using the Global Search API this way but I would look at two things:

    If you see multiple columns in your popup list, but the others are empty:

    •  what is defined as the return from Global Search (if you use the Global Search on the UI you only get back the Name field and Module is that all that the API returns from the matching beans?) Try to reverse-engineer the API: 

      clients/base/api/UnifiedSearchApi.php

    If you only see one column in the popup list:

    • what fields do you have in the PopupViewList for your Product Catalog? Go to Admin->Studio->ProductCatalog->Layouts->PopupView->PopupListView

    Hope this helps,

    FrancescaS

  • Hello Francesca Shiekh,

    Thanks for the response.

    The issue was because the ProductTemplates/globalsearch endpoint was not returning all the fields in the response; instead it was only returning those fields which were defined as "searchable" in Studio.

    As you can't put manually from studio some field types to be searchable, I had to do it manually, like this in custom/Extension/modules/<module>/Ext/Vardefs/customGlobalsearchFields.php:

    $dictionary['<module_name_singular>']['fields']['<my_field_name>']['full_text_search']=array (
        'enabled' => true
    );

    Then perform Quick repair & rebuild & then perform a system search reindex.

    However, the real issues are coming because I'm not able to:

    1. paginate the results in the selection-list layout.
    2. apply any filters

    I guess it's because we put the following options in the context when creating the drawer:

    filterOptions:{
        auto_apply:false
    }

    And then, filters and pagination breaks. But if we don't pass this option, then when the drawer opens, filters are applied and the custom result from the collection disappears.

    Have you been able to resolve this in any way or happens to you too?

    Thank you.

    Regards,

    David.

Reply
  • Hello Francesca Shiekh,

    Thanks for the response.

    The issue was because the ProductTemplates/globalsearch endpoint was not returning all the fields in the response; instead it was only returning those fields which were defined as "searchable" in Studio.

    As you can't put manually from studio some field types to be searchable, I had to do it manually, like this in custom/Extension/modules/<module>/Ext/Vardefs/customGlobalsearchFields.php:

    $dictionary['<module_name_singular>']['fields']['<my_field_name>']['full_text_search']=array (
        'enabled' => true
    );

    Then perform Quick repair & rebuild & then perform a system search reindex.

    However, the real issues are coming because I'm not able to:

    1. paginate the results in the selection-list layout.
    2. apply any filters

    I guess it's because we put the following options in the context when creating the drawer:

    filterOptions:{
        auto_apply:false
    }

    And then, filters and pagination breaks. But if we don't pass this option, then when the drawer opens, filters are applied and the custom result from the collection disappears.

    Have you been able to resolve this in any way or happens to you too?

    Thank you.

    Regards,

    David.

Children
  • Yes, I have the same problems with pagination and filters. If I use the filter on the selection list the filter it goes back to using the full collection, not just the one I created.

  • Hello Francesca Shiekh,

    After some hours of research and testing, I've come up to the following solution:

    initialize: function(options) {
        this.plugins = _.union(this.plugins, ['LinkedModel']);
        this._super('initialize', [options]);
       
        //Example of use
        this.search( 'ProductTemplates', 'revenuelineitem_templates','what I want to search' );
    },

    /**
    @param module: The module of the collection you want to retrieve records from
    @param linkModelRelName: the name of the relationship between the module you are opening the drawer from and the module of the drawer you are opening
    @param query: the query you want to search in the globalsearch endpoint
    **/

    search: function(module, linkModelRelName, query) {
        var self = this;
        var model = self.model;
        var pt = app.data.createBeanCollection(module);
        //Set the endpoint from which the collection will fetch the data
        pt.setOption('endpoint', function(method, collection, options, callbacks) {
            //Filters on the 'selection-list' view will not work depending on your endpoint
            var params = options.params;
            //This way I concatenate in the query to the globalsearch endpoint the 'name' filter that I'm using
            //in the selection-list view - rest of the filters don't work for this endpoint
            if (params.filter && params.filter[0].$or[0].name.$starts) {
                params.q = query + " " + params.filter[0].$or[0].name.$starts;
            } else {
                params.q = query;
            }
            var url = app.api.buildURL(module, 'globalsearch', null, params);
            return app.api.call('get', url, null, callbacks);
        });
        app.drawer.open({
            layout: 'selection-list',
            context: {
                module: module,
                parent: self.context,
                model: self.createLinkModel(model, linkModelRelName),
                collection: pt,
            }
        }, _.bind(self.recordSelected, {
            model: model
        }));

    },
     
    //Here you will retrieve the record selected in the 'selection-list' view
    recordSelected: function(recordSelected) {
        console.log('RECORD SELECTED! ' + recordSelected);
    }

    Created this gist with the code.

    What i'm doing here is to set to the collection the endpoint that I want to search from, in my case the "ProductTemplates/globalsearch" one.

    Note that I've removed the 

    filterOptions:{
        auto_apply:false
    }

    options.

    This way, I pass to the selection-list layout my collection and the collection searchs in the endpoint, what fixes the pagination

    In my case, custom filters do not work, because you actually can't filter using the "globalsearch" endpoint. I mean, you just can't apply filters to a custom collection, because filters actually filter on the full list of records of a module. However, I've set up my function to apply the "Name" filter of the "selection-list" to my globalsearch query each time I filter in the selection-list view.

    This way, at least, you can search using the globalsearch endpoint, apply the "Name" filter of the selection-list view to the query and pagination works.

    Hope this helps and if anyone needs help just tell me.

    Regards,

    David.