Pagination is used to efficiently retrieve large sets of search results in smaller, manageable chunks. This approach helps to avoid performance issues and memory constraints while processing significant amounts of data.
Pagination in the context of a saved search refers to the technique of dividing a potentially large set of search results into smaller, manageable “pages.” Each page contains a subset of the total results, and users can navigate through these pages to access the data they are interested in. Pagination is commonly used to improve the user experience when working with databases or systems that return a significant number of results, as it helps prevent information overload and enhances performance.
A sample code is provided for the understanding of pagination concepts.
let customerSearch = search.create({
                    type: search.Type.CUSTOMER,
                    filters: [
                        ["stage", "anyof", "CUSTOMER"],
                        "AND",
                        ["custentity_jj_latest_sales_order", "isempty", ""]
                    ],
                    columns: [
                        search.createColumn({ name: "internalid", label: "Internal ID" })
                    ]
                });
                let customerSearchResultIds = [];
                let lastPage = false;
                const pageSize = 1000; // Number of records per page
                let pageIndex = 0; // Index of the current page
                // Iterate through each page of results
                while (!lastPage) {
                    let pagedCustomerSearch = customerSearch.runPaged({
                        pageSize: pageSize,
                        pageIndex: pageIndex
                    });
                    pagedCustomerSearch.pageRanges.forEach(function (pageRange) {
                        let page = pagedCustomerSearch.fetch({ index: pageRange.index });
                        if (page.data.length < pageSize) {
                            lastPage = true;
                        }
                        page.data.forEach(function (result) {
                            customerSearchResultIds.push(result.getValue({
                                name: "internalid",
                                label: "Internal ID"
                            }));
                        });
                    });
                    pageIndex++;
                }
                return customerSearchResultIds;