Announcement

Collapse
No announcement yet.

How to get full response of the this.collection.fetch() method

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get full response of the this.collection.fetch() method

    HTML Code:
    this.getCollectionFactory().create('Subscription', (newCollection) => {
      this.collection = collection;
      this.newcollection = newCollection;
      .....            // some where conditions, should return lets say 40 records
      this.newcollection.fetch().then((response) => {
    
    //This response has 2 things, list and total. the list is an object of 20 records as arrays and the total displays 40
    
        const responseData = response;
        let entityIdList = responseData.list.map(item => item.entityId);
        this.whereCondition = [{.....}]; // using entityIdList in whereCondition
        this.collection.where = this.whereCondition;
    
        Espo.Ui.notify(this.translate('pleaseWait', 'messages'));
        return this.collection.fetch()  // because whereCondition has only 20 records, it displays only those
      }).then(() => {
        Espo.Ui.notify(false);
      });
    }, this);​
    this.collection.fetch() method fetches 40 records, but when you try to get the records via response, it contains only 20 records in the list.

    Is there any other way to get the fetched data or get all the records via response?
    Last edited by Prathyush Shetty; 01-09-2024, 01:09 PM.

  • #2
    You need to specifiy the size, try this before fetching the colltcion

    PHP Code:
    this.collection.maxSize this.getConfig().get('recordsPerPage') || 20
    Rabii
    Web Dev

    Comment


    • #3
      rabii It solves the issue, but not completely. records per page is also set to 20.

      I changed my code
      PHP Code:
      this.collection.maxSize 50 

      So now the response has all the 40 fetched records. However, the problem persists when the fetched data exceeds the maxSize. If I modify the where condition which fetches me 8345 records, the response will have only 50 records. Also, the count displayed on the UI is 50.
      Is there any way to make it dynamic?
      Last edited by Prathyush Shetty; 01-09-2024, 12:28 PM.

      Comment


      • #4
        Try this, assign the collection total to the collection maxSize

        PHP Code:
        this.collection.maxSize this.collection.total
        Rabii
        Web Dev

        Comment


        • #5
          I think you might need to call the length function instead, the total function will count the total number of records in the backend. If total doesn't work try to return the length

          PHP Code:

          this
          .collection.maxSize this.collection.length



          Rabii
          Web Dev

          Comment


          • #6
            rabii I did the same thing. It goes on to set this.collection.maxSize = 0, and displays "No data" on the UI. I think this.collection.total is set to 0 before the data is fetched. I'm not sure if that's how it works.

            Comment


            • #7
              rabii Tried setting maxSize to total as well as length, neither of them gave me proper results. Both resulted in "No Data" as maxSize was set to 0.

              Comment


              • #8
                Can you share your code here, i don't understand what you are trying to do with your code.
                Rabii
                Web Dev

                Comment


                • #9
                  maxSize should work. But it's limited server side with "recordListMaxSizeLimit" parameter. Set to 200 by default. https://docs.espocrm.com/administrat...arams/#general

                  Comment

                  Working...
                  X