Skip to main content

Notifications

Community site session details

Community site session details

Session Id : LnSgXpCLxBUC+Qi+P2JWeE
Power Pages - Customize & Extend
Answered

Fetch XML pagination

Like (0) ShareShare
ReportReport
Posted on 2 Dec 2022 08:42:32 by 17

Hey guys,

 

So I've been struggling with the following issue in the last days.

 

I have a huge photo library that I want to display to users (+200 photos). Those photos are stored in Dataverse in a base64 code. They are not huge in size, only about 200-300kb.

 

I am using then a fetch xml to get the photos and display them in the portal. The issue I'm having is that the portal can't display all of them (because of the combined size, I guess) and it stops at some point.

 

I tried paginating them using this article and it works fine for the first page, but I'm struggling with navigating to the second page.

If I do it manually, like this; it works.

 

<a href="?page=2">Next page</a>

 

 

But if I try to set the page variable to plus 1, it doesn't do that. 

 

<a href="?page={% assign page = page | plus: 1 %}">Next</a>

 

And it shows this error: Liquid error: Input string was not in a correct format. 

 

This is the whole code, maybe it helps. 

 

{% assign pagingCookie = request.params['paging-cookie'] %}
{% if pagingCookie %}
 {% assign pagingCookie = ' paging-cookie="{{ pagingCookie }}"' | liquid %}
{% endif %}
{% fetchxml bag_query %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" {{ pagingCookie }} page="{{ request.params['page'] | default:1 }}" count="10">
 <entity name="bg_bag_detail">
 <attribute name="bagdescription" />
 <attribute name="autoid" />
 <order attribute="autoid" descending="false" />
 <filter type="and">
 <condition attribute="statecode" operator="eq" value="0" />
 </filter>
 </entity>
</fetch>
{% endfetchxml %}

{
 "morerecords": {{ bag_query.results.more_records }},
 "paging-cookie": "{{ bag_query.results.paging_cookie }}",
 "paging-cookie-encoded": "{{ bag_query.results.paging_cookie | escape | url_escape }}",
 "page": {{ request.params['page'] | default: 0 }},
 "results": [
 {% for item in bag_query.results.entities %}
 {
 "bag_description":{{ item.bagdescription }}
 }
 {% unless forloop.last %},
 {% endunless %}
 {% endfor %}
 ]
 }



<a href="?page={% assign page = page | plus: 1 %}">Next</a>

 

 

Basically I'm stuck and I can't find a way to go to the next page. 

Please help 🙂 

Categories:
  • Verified answer
    SimperingLemon1 Profile Picture
    17 on 06 Dec 2022 at 16:22:30
    Re: Fetch XML pagination

    Hi Fubar,

     

    Thank you for your reply.

     

    This bit has actually pointed me in the right direction.

     

    I don't really know why, but it seems like all the variables are stored as strings and I wasn't able to do any math on them. I ended up using the following code to convert them to a integer.

    {% assign page = page | integer | plus : 0 %}

    After that I was able to keep adding to this and navigating to further pages.

     

    I'll attach the code below as a reference.

    {% if request.params.page == nil %} <!–– this bit is only for setting the first page to 1, and then adding a +1 to get to the second page --> 
     {% assign page = 1 %}
     {% assign page = page | integer | plus: 1 %}
     {% else %} <!-- this bit is for the next pages --> 
     {% assign page = request.params['page'] %}
     {% assign page = page | integer | plus : 0 %}
     {% assign page = page | integer | plus: 1 %}
    {% endif %}

    And then I'm using your suggestion for the hyperlink. 

    Works like a charm.

     

    Thanks again!

  • Verified answer
    Fubar Profile Picture
    7,867 Super User 2025 Season 1 on 06 Dec 2022 at 00:52:31
    Re: Fetch XML pagination

    @SimperingLemon1 wrote:

     

    But if I try to set the page variable to plus 1, it doesn't do that. 

     

     

    <a href="?page={% assign page = page | plus: 1 %}">Next</a>

     

     

    And it shows this error: Liquid error: Input string was not in a correct format. 

     


    Assign just assigns it does not output.  You need something like

     

    {% assign page = page | plus: 1 %}
    
    <a href="?page={{page}}">Next</a>

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Pages - Customize & Extend

#1
Ajlan Profile Picture

Ajlan 4

#2
Fubar Profile Picture

Fubar 2 Super User 2025 Season 1

#2
CBDEV Profile Picture

CBDEV 2

Overall leaderboard

Featured topics

Loading started