top of page
Neon Smoke
Writer's pictureAngeliki Patsiavou

RegEx Sentence Casing in Power Pages

In a previous blog post, I showed you how to impose sentence casing in your Dynamics 365 instance/ Model-Driven App through a Power Automate flow. This means that when your CRM user inserts a First Name like mAria or MAriA, this will automatically change upon saving the record. Super helpful on top of any recommendation or tooltip configuration. Even if you train users, you still cannot guarantee the data entry outcome or the impact on downstream systems. Thus, the flow supports your data hygiene in the background.

I am Lost – What is there more to say?

What if we also had a Power Pages portal requiring external end users to input data that go back into our CRM app? Our flow would still trigger in retrospect. However, it still means the first version of the saved record does not have sentence casing in any impacted name fields. Secondly, and most importantly, our Power Automate flow will run.

What if there was another, even easier way, within Power Pages directly? You are in luck!

There is a way where you can impose data validation logic in any column of a Power Pages form before even saving it. In this case, we will cover the sentence casing scenario. Our tool of choice to navigate this confusing island: Regular Expressions aka RegEx.


Show me the miracle!

The first thing we need to do is locate our Basic Form that our impacted column is in. We will continue to be working in our Avenge 365 custom Model-Driven App and our S.H.I.E.L.D. Declassified Power Pages portal.


Our impacted column will be the Battle Title which is meant to have a code name such as Atlas. Of course, we do not want to spell it aTlas or ATlas etc. by accident.


To get there, let’s first open the Basic Form as discussed and go to the Basic Form Metadata tab.

Next, click on + New Basic Form Metadata.

Once this Basic Form has opened, we need to define the column this validation logic will be about.


In Type, choose Attribute.


Then, choose from the dropdown in the Attribute Logical Name the column you want to configure. In this case, as we mentioned, it is the Battle Title

After you are done, scroll down to the Regular Expression section of the General tab.

Here is what you will need to type in: ^[A-Z][a-z]*


Let’s analyze what this means though:

  • ^[A-Z]: This part of our expression ensures that the first character of the Battle Title string is an uppercase letter.

  • [a-z]*: This part of our expression ensures that the following characters of the Battle Title string are all lowercase letters.


On top of this, we will add a Regular Expression Validation Error Message. This will help end users to understand, should they not sentence case the Battle Title, why they are unable to submit the Basic Form in the Power Pages portal. Remember, we should be kind to our end users instead of creating dead-end error screens.


Add a simple sentence such as Please use sentence casing for the Battle Title.

Bonus Tip

To make this an even more seamless end user experience, we will also apply a description for the column. This will help the user know in advance they have to sentence case the Battle Title so they can avoid the error message.


In the same General tab, scroll up just above to the section Description/Instructions

Choose Yes in Add Description.


In Position, choose Above the field. You also have the option to add it Below the field or Above the label.


Unless you already have a description from your maker portal that satisfies your needs, choose No in Use Attribute’s Description Property.


Finally, add in the Description something like Please sentence case your Marvel-lous name!

Click Save & Close for the Basic Form Metadata, and then again for the Basic Form itself.

And that is it!


Ready to get out of this maze?

Let’s test drive this. After heading over to our Power Pages Portal, let’s try and create a Battle record.


If we were to not sentence case a new Battle Title with something like aTLas, we would see two things:

  1. Pre-trying to submit the form, you will see the description over the field value.

  2. Post-trying to submit, the validation error message appears at the top of the form. This is why it is important to be specific in the message about the field impacted incl. its name.

Happy sentence casing!


170 views2 comments

2件のコメント


ゲスト
11月04日

Regex will also allow you to enforce a bunch of weird formatting as well using the same functions, makes life a lot easier than writing a bunch of JS! Great stuff :)

いいね!

This is very nice thanks for sharing! 🥳

いいね!
bottom of page