Power Pages

2 Liquid tips – Generate GUIDs and base urls in Power Pages

In this post I’m looking at Power Pages and how to get the base url of my site and generate Guids in Liquid.

Power Pages development

Ok, first of all, Power Pages development can be challenging for many. It really helps if you are good at the following technologies:

  • HTML
  • CSS
  • JavaScript
  • Dataverse
  • Liquid

Now assuming that you have a basic understand of the above, I’ve got 2 quick tips to hopefully make your Power Pages development a little bit easier.

Tip 1 – Get your Power Pages URL

Consider that on one of your pages you have the following url used within a link:

<a href="https://myppsite.powerpages.com/paymentinvoice">Place Order</a>

Now when you deploy this to a different environment that base url part will change. However you wouldn’t want to have to edit the pages. Especially if you have many pages with these kind of links.

The better option is two rewrite your code a bit. Using a base url is better:

<a href="{{baseurl}}/paymentinvoice">Place Order</a>

So now we will need to get a base url. This using liquid filters this is actually very easy. A single one liner will do.

{% assign baseurl = request.url |split: request.path | first %}

So qwe take the current page url split this by the current page url so that we get an array with the base url and the query strings. Then by piping this into the first function we take the base url.

Tip 2 – Create a unique ID

Within Liquid you might want to generate a guid sometimes. Unfortunately there isn’t a function Guid() available like in many other languages.

But what if you want to create record using a form and then a few pages down the user journey, you want to update that same records again. Being able to pass a unique ID from one page to another can be quite useful.

I’ve seen some solutions by using the current date and time, however two users clicking your buttons at the same time would mess things up.

In this case we have a URL on a page that calls a page where we want to create a booking. Now to generate a unique booking id we would generate a unique if like this:


Out of interest I also tried to use AI to give me the answer, but new_guid doesn’t exist in Liquid:

Last week when I searched for the same the AI expert came up with something like this:

'xxxxxxxxxxxxxxx' | replace: 'x', '01234567890abcdef'

But once again that also didn’t work as each x will be replaced with all 16 characters.

&bookingid={% for character in 'xxxxxxxxxxxxxxx' %}{{'01234567890abcdef'| shuffle | first }}{% endfor %}

So now we have a GUID that isn’t following the standard guid format. Just with a bit more liquid logic we can generate a proper GUID.

&bookingid={% for character in 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' %}
  {%if character =="x" %}
    {{'01234567890abcdef'| shuffle | first }}{% endif %}
  {%if character != "x" %}
  {% endif %}
{% endfor %}"
Pieter Veenstra

Business Applications Microsoft MVP working as a Principal Architect at HybrIT Services Ltd. You can contact me using contact@sharepains.com

Recent Posts

1 Step to create the REPT function in Power Automate

Today I was asked on the chat about how to create a REPT function in…

2 weeks ago

4 avoidable pitfalls of Low Code development?

Low Code Development is all about anybody can do it! But what are the pitfalls…

4 weeks ago

Implement booking availability in Power Apps in less than 5 minutes

Today I was asked how to implement a booking availability solution in Power Apps. The…

3 months ago

Delegation with SharePoint lists Power Apps vs Power Automate

We all know about delegation warnings in Power Apps, but how about delegation with SharePoint…

3 months ago

Timing issues in relation to App OnStart, Screen OnVisible, Timers and user interruptions in Power Apps

When you create apps, it is important to understand the timing issues that may happen.…

3 months ago

Implement a PDF preview in a Model Driven Apps

Recently I needed to implement a PDF preview in a Model Driven App. This should…

3 months ago