Power Apps form data validation tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is reza durrani today's video is focused around data validations in powerapps we will cover various validation scenarios including required field validations conditionally validating data cards date validations pattern matching validations and much more so let's get started with the video but first my introduction so let's begin with data validations in a form control in powerapps in this scenario i have a very simple form control in my powerapp the data for which is coming from a sharepoint list i have leveraged the microsoft lists template called asset manager to generate this list it's a list of assets that i can maintain and it comes with a wide variety of column types i have made certain changes to the list schema title here is a mandatory field the purchase price which is of type currency i have made it a mandatory field in my data source itself back to the power app we have a gallery that is showing me all the assets that are currently available in the asset manager list for each asset we have the title which is the tag associated with the asset that i'm defining right here and i have the other metadata highlighted right here in the gallery template create a new record in my asset manager list now in this case because i've created this form control from that sharepoint list which is asset manager i have two mandatory fields which is title and purchase price and as you can see both of them have this asterisk symbol next to them if i try and submit my data right now it will tell me that an entry is required or has an invalid value now this is the standard message that you get based on required field validations based on fields that you have identified as required in your data source now let's see how we can add additional validations to this existing form control now if you look at for example the asset type column right here by default this as part of the data source is not identified as a required field however if i head over to the advanced tab by selecting the entire data card for asset type i have the option of searching for a property called required and by default when you add a form control all the data cards are locked and they are locked since all the properties are dependent upon the column type defined in the data source in this case the required column is locked and it is false if i want to make changes to this i have to unlock the card and then i can make a change to it right here so i can say that yes this is a required field as well now bear in mind this is not a required field in my back end sharepoint list but i have made it required right here in the form control itself that means in the form control i can add additional layers of validations or restrictions that are not defined in my backend data source so i can make it more restrictive but i cannot make it least restrictive if i go to the title data card and let's say i unlock this card as well and head over to the required property and set this as false title acts like it is not required however if i try and submit the form right now notice that it pops up that title is actually a required field that is because title is required in my back-end data source so even though i went ahead and turned it off when this is not required it is still enforcing what the data source is enforcing so let's go back and change title to be a required field again now the next step is how do i add required field validations conditionally that means depending upon something that's taken place in the form i would like a certain data card to have a required field validation so let's take a very simple use case here if the purchase price is above let's say 250 so anything above two fifty dollars business justification would be a required field now as you can see this card is locked so i would have to first unlock this and if i head over to the required property for this data card it is false by default i need to make this required only if the purchase price is greater than or equal to 250. so how do i do that if i select the control within this data card this is the text control so i'm just going to copy the name of this text control i'll head back to the required property for business justification and set this as if the data card value dot text now i know that it's going to be a number because it's purchased price so what i can do right here is typecast this with value right so value of the text that's coming from purchase price if this is greater than or equal to 250. now if i go ahead and play this app and let's say i change the purchase price to 250 you will note that the moment i do that business justification becomes a required field and the moment the number goes below 250 business justification now is not a required feed so you can conditionally make fields required based upon your scenarios now let's pick the serial number column right here now if i look at the back end data source serial number is a single line of text column it's a simple text field so the user is free to enter any text of their choice however what i would like to do right here is i would like to put a validation that says if the user enters a serial number the serial number can only be numeric and at the same time it must be nine digits so how do we go about doing something like that now typically what i observe is we add additional labels we add some calculations we add some logic and we show the error message if that condition is met and then we even go ahead and disable the submit button by trying to add that similar logic there so the user cannot submit until that validation is met however when you do things like that you are adding additional controls to your powerapps form please bear in mind that the form control itself the data cards each card has five controls it has the main card and then it has four additional controls that it comes with one is the label text the data card value is where the user can interact with that card error message shows up if there is any error associated with that card and then star visible basically shows up if the field is a required field so anytime you add a card you're going to get these four controls plus you get the card of course in which these controls are baked into so five controls per card and if you keep adding additional labels additional controls you are adding more controls to your power app and you need to be mindful that there are certain performance considerations as well the recommendation from microsoft is not to go beyond 500 controls in your power app we have the error message label already in place why not leverage that existing label to add our own validations into that label so how do we go about doing that so here's my serial number card of course if i want to make any change i need to unlock this card so i'm going to go ahead and unlock this card and this card has an error message label now by default the error message label the text property is set to parent dot error that means if there's any error that comes in from the backend data source let's say this is a required field there's an error it's going to show up right here there's a function called coalish and what colas does is it basically picks up the first non-blank argument that you provide to it and when you're displaying error messages you never want to display five or six error messages associated with one control you would like to go in order right let's say serial number is mandatory so make sure you fill it if the number is not nine characters we need to display a message if it contains alphabets we need to display an error message so we can define that order right here in the corliss function so the first one is of course parent.error comma now i can add my my own validation logic right here now what i would like to do in my case is the serial number has to be the user can only enter numbers now if i select this text input control i'm going to copy the name of this text input control go back to my text function for my error message label now i want to check for a pattern here the pattern is that it has to be numeric in powerapps there's a very useful function called is match and this is the official documentation on docs.microsoft.com highly recommend you to check this out any sort of pattern matching that you would like to incorporate you can leverage the is match function and what is match function does is it goes ahead and matches a pattern that you define associated with the text that you provide to it and not just that it comes in with a lot of predefined patterns that you can leverage and all of these patterns are backed by regular expressions it comes with so many useful regular expression patterns that you can leverage directly in your apps so in my case i only need the user to enter numbers basically i want the user to enter multiple digits so as you can see there is a predefined pattern for this called multiple digits so i'm going to go ahead and leverage this pattern which matches one or more digits so let's go back to the powerapp and right here i need to show a message if an error occurs so what i'm going to do is this i'm going to use not of is match that means it is not matching the pattern that i'm defining so is matches the function it's asking me for the text text is nothing but that data card which is my serial number data card which is my text control and now it's asking me for the format and this comes with all those predefined formats that was there in the microsoft documentation itself and one of the predefined formats is multiple digits i'm just going to leverage this if the text does not match the pattern that i have defined in that case in that case i would like to show an error message only numbers are allowed so i formatted my function right here so now let's go ahead and play this app if i start plugging in values here so let's say i just put in one number the message went away now i can keep adding additional digits as long as i'm entering numbers it's good the moment i enter any special character i enter any alphabet immediately it's going to throw me that error message saying that only numbers are allowed now even if it is empty it's still showing only numbers are allowed so how do i handle that case all i have to do in this case is just add an additional check right here and that check is whether or not that same text control should not be blank that means if the text control is not blank and it does not match this pattern only then go ahead and show this message so if i now play the app i won't see that message because serial number is empty right now or blank and the moment i start plugging in any values in there if they are not numbers it's going to throw that error message for me another thing is if i was to go ahead and submit this right now notice that wherever there are errors let's put this red border around it i want that same behavior right here for the serial number case as well if i select the control and if i head over to border color you will note that the formula says if is blank parent.error put the standard border color otherwise make it red so how do i change this so it reflects the changes that i made to the error message label well all you have to do is go ahead and copy the control name for the label in my case it's error message six i go back to my text control and for the border color it says if isblankparent.error just replace this with the error message dot text that's it if i play this right now notice it's put the red border around it that only numbers are allowed and the moment i enter correct data the border will vanish let's say i would like to add another validation that the serial number has to be nine digits so i want to add a second validation to this the way i can do that is exactly the same i'm going to go back to my error message i already have the coalesce function defined so here's my first conditional check now all i have to do is add my second conditional check right here add a comma and then add your next condition and this is what my next condition looks like so i'm checking to see that if the card is not blank and there's a function called length which gives me the length of the text that i provide to it and if the length is not equal to nine then i would like to show an error message that says it must be nine digits so let's go ahead and play this right now it is already giving me that error message the moment i put in a nine digit number that error message goes away if i was to enter a character that's not a digit the other validation will kick in and if i don't provide nine digits of course it's going to handle that as well so that's how you can add multiple conditions and utilizing the same standard error message variable that is provided from a data card now the next case is for the title column which in this case i have called it asset tag whenever an asset is added it has a tag associated with it and when the user creates an asset they have to select the asset type and let's say i want to create a validation wherein if the asset type is accessory the asset tag has to begin with the characters ac if the asset type is laptop the asset tag has to begin with the letters lt i have my data cardio for title that i have unlocked and for this card i have the error message label which is parent.error same scenario as before i will go ahead and add the coalace function and i've gone ahead and plugged in my formula my formula is the switch function i'm switching on the combobox control right here which is the asset type if that control.selected.value is laptop then i've gone ahead and checked to see if the title text control if it does not start with lt then i'm displaying a message that the asset tag must begin with lt if the user has picked accessory then i'm checking to see if the asset tag is not starting with ac in that case i'm displaying this error message that says the asset tag must begin with the letters ac now once i've done this if i go ahead and play this app right now notice right now it's not displaying an error message because i've selected laptop and it is lt but if i was to change this to any other value let's say i change this to ac it throws me the error message that says asset tag must begin with lt and if i was to change this to accessory i won't get an error message because it is matching the criteria that i have defined in my validations now another case that i would like to add to my asset numbers that the user enters is that the user has to enter something which follows a specific pattern now if you look at the documentation once again around the is match function it covers a wide variety of patterns that you can leverage straight away so for example let's say i want to check to see if the text that the user enters matches the social security number here is the formula for it just copy this and paste it that's all you got to do if you want to check if something matches an email address format here's the formula for it right if something matches a particular sequence it should have digits a period and then a zero or more digits all of these patterns are defined right here i can define my own pattern so let's say my pattern is the first two characters have to be letters and the next four characters have to be numeric once again back to my coalesce function i will go ahead and add another condition right here and this is what my new condition looks like i'm first checking to make sure that the text value in that title column is not blank and if this value the text that the user has entered does not match the pattern that i'm defining now what's my pattern i want two letters and four digits and this is all what i have to do and literally all i've done is followed the same patterns that are defined right here but modified it based on my requirements i want two letters so i'm matching with a couple of letters first and then i'm matching it with four digits now if i go ahead and play this now notice it says the first error message i'm getting is that asset tag must begin with lt that's because i've selected laptop makes sense so i'm going to change this to laptop now the moment i do this i get a different error message it says the first two characters must be alphabets and the next four characters must be digits so i have to enter digits right once i complete that scenario only then it is going to go ahead and accept it if i add another digit to this or if i don't follow the pattern that's defined it will immediately throw me that error message right there another common use case is around dates so i have a due date column that's right here wherein the user can go ahead and pick dates so the date has to be greater than today and less than or equal to 90 days from today that's my use case my due date data card i will unlock this and go to the error message label so here's the formula that i've plugged in i'm checking to see firstly if the date is not equal to blank and then i'm checking to see if the date that the user has entered if it is less than or equal to today or if the date is greater than or equal to i'm using date ad so it will add days to today's date that's adding 90 days to today's date so if the date is greater than 90 days from today or the date is less than or equal to today then i would like to display that error message and that's the message that i'm displaying right here now if i play this app so let's say i pick today's date and say okay notice it throws me that error message right away because the date has to be greater than today if i pick a date on the past it's going to throw me that same error message if i pick a date that is within the time span that i have defined it won't show me that error message and if i go beyond 90 days from today it will go ahead and showcase that error message right here so here's another validation that i just added i'm checking to see that if the date that the user has entered there's a function called weekday which gives me the day of the week in my case i want to start my week from monday if the day is greater than five that means it's either saturday or sunday then i'm going to display again a message saying that the date must be a weak day now if i play the app right now right now showing me an error because the date i entered is greater than 90 days from today so let's say i pick a date in feb if i pick the fifth of feb which is a friday it's not a weekday it works and the moment i pick a day that is not a weekday it's going to throw me that error message right here now one more use case i have a column called order number and the user can only enter numbers here they should not enter decimals my column here the order number is a number type column now of course in your back-end data source you have options right you can say okay i don't want any decimal places or i need decimal places but what if you want to restrict it right here so it only includes numbers and this is something that we've already done if i go back to the error message here in this case once again i've plugged in my formula my formula is if the text that the user has entered is not blank and if the text does not match the pattern of multiple digits that means only digits are allowed i'm going to display my error message which says only numbers are allowed no decimal so if i head back right here the moment i start plugging in my order number it works fine if i include a decimal point there you go it's going to pick that up and tell me that it's not allowed so let's say i enter my order number with a decimal and in my case my asset is going to be a laptop i'm going to give it an asset tag i'm going to fill in all the mandatory fields now notice right here i said only numbers are allowed no decimals all the validations that i put in are for my own form control these are not validations that are added to the backend data source these are in the power app itself i have added the validations right here now the user is still allowed to submit that may not be the best experience so what i can do in this case is for every error message label that you have customized so in my case i have customized the card order number all i need to do is just copy the label name go to the submit button and let's make sure that the submit button is disabled if there is an error message so what do i do in this case so if the error message in my case nms is 13 which is related to the order number if that is not blank that means it has a value that means there's an error go ahead and disable the button or keep the button in edit mode now if i play this notice right now it's disable the button that's because the user has to fix the error the moment i fix the error the button will come alive now i have linked it just to the order number function for example the date column you see i'm getting the error message but i'm still allowed to submit because my backend data source technically allows me submitting a date associated with the weekday so once again if i would like to block this as well very simple just go to the error message copy the label name and what i did in this case is added another condition here which is an or condition that says whether the error message label for the date control if it does not blank then go ahead and disable the button and notice the button is now disabled until the user enters an accurate date one final case that i would like to cover is around uniqueness in your data source so let's say i would like the asset tags to be unique so in my case right here i already have asset tags that i am defining so in my case i have an asset tag here for laptop surface pro x which is lt27350 so if i go right here and create another record and let's say i pick asset tag lt2735 i would like to validate whether this asset tag is already existing in the backend data source or not now in sharepoint you can define uniqueness for a column you can set the properties of the column to be unique and that's exactly what i've done so if i actually try and submit this after filling out all the mandatory fields so if i try and submit this notice it throws me an error which says that the list item could not be added or updated because duplicate values were found in the field title that's because i actually made that column a unique column in my data source itself so if the data source allows you to add those sort of validations go ahead and do that here's another case purchase price i'm going to enter a very high purchase price notice in the data source itself i have defined the min value and the max value so it's clearly telling me that the purchase price value must be between one and five thousand so if you can handle things in your columns in your back end just go ahead and do that if not you can always add the validation logic right here as i showcased throughout this video so these were all the different types of validation scenarios that i covered as part of this video i hope everyone enjoyed this video if you did then do like comment and subscribe to my youtube channel and thank you so much for watching
Info
Channel: Reza Dorrani
Views: 125,692
Rating: undefined out of 5
Keywords: power apps form validation, powerapps forms validation, validate microsoft powerapps forms, microsoft powerapps data validation, Power Apps form data validation tutorial, powerapps validation on submit, powerapps validation form, powerapps data validation, powerapps form validation on submit, powerapps validation, powerapps validate field, powerapps validate form before submit, validation in powerapps form, data validation in powerapps, power apps, powerapps
Id: XvevCq6qhX4
Channel Id: undefined
Length: 23min 36sec (1416 seconds)
Published: Tue Dec 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.