findAll method of DataService class returns only 100 entities

穿精又带淫゛_ 提交于 2019-12-04 06:36:54

问题


We've successfully migrated our v2 QBO to v3 and after that on the production we got an issue from one of our customers. They have over 100 their customers in QBO account. And they want to copy them into our application. We implemented an import like this:

    DataService service = getDataService(owner);  // obtain DataService via Access Keys
    List<com.intuit.ipp.data.Customer> customers = 
         service.findAll(new com.intuit.ipp.data.Customer()); 
    for (com.intuit.ipp.data.Customer customer : customers) {
        createCustomer(customer, owner);  // this is our internal method to create
    }

As mentioned in Class Library Reference - method findAll is a

    Method to retrieve all records for the given entity.

But our customer is getting only first 100 entities (Customer's) from his QBO v3 account. And if he do the same import operation - he will get the same first 100 entities again. This method doesn't allow any pagination options.

So the question is, how to get all of the entities?


回答1:


You should use Query endpoint with page filters.

The following query gets customers 1 - 10:

String query = select($(customer)).skip(0).take(10).generate();

Output - SELECT * FROM Customer STARTPOSITION 1 MAXRESULTS 10

The following query gets customers 21 - 25:

String query = select($(customer)).skip(20).take(10).generate();

Ref - https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0201_ipp_java_devkit_3.0/0011_query_filters#Pagination

finally

QueryResult queryResult = service.executeQuery(query);

Thanks




回答2:


To fetch all of customers for a specified business, first you need to get their count, and then, as mentioned at the previous answer, get the customers by "take" method:

        Integer customersTotal = service.executeQuery(selectCount(_customer).generate()).getTotalCount();
        QueryResult queryResult = service.executeQuery(select($(_customer)).skip(0).take(customersTotal).generate());
        List<? extends IEntity> entities = queryResult.getEntities();
        for (IEntity entity : entities) {
            if (entity instanceof com.intuit.ipp.data.Customer) {
                createCustomer((com.intuit.ipp.data.Customer) entity, owner);
            }
        }


来源:https://stackoverflow.com/questions/22909923/findall-method-of-dataservice-class-returns-only-100-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!