Set Default Values in Power Apps | Dropdown, Lookup, Choice, Date | SharePoint

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone raza here in this video i will show you how to set default values for controls in power apps default to current user today's date choice columns lookup columns multi-select choice columns default to please select and drop downs and a lot more so let's check it out in action [Music] let's start with the text input control the text box control has a property called default and by default it is set to text input i can set it to blank this i can replace with any text i can even make this dynamic for example i would like to show the current logged in user's full name next let's focus on the date picker control there is a property called default date by default it is set to today's date if i remove this in that case the date that it is showcasing here comes from a property called input text placeholder which has the following formula and this is just a placeholder text which i am free to change i have set the placeholder text to select date so the date control here shows the text select date i can also default it to scenarios like three days from today or a week from today and so and so forth for that i can leverage the function date add i would like to add to today's date let's say seven days and the unit here would be days so this will now add seven days to today's date and set it as the default date with the date add function the unit options that are available are plenty days months quarters years and a lot more set the default date to the first date of the current month we can leverage the date function for the year i can use the year function and supply it today's date the month would be month after day and then the day would be the first so that would set the default date as the first date of the month if i would like to change this to the last date of the current month i will add one to the month and i will set the day as zero so this now sets the date field to the last day of the current month maybe you need the last day of the next month so i can simply here do month of today plus two comma the day is zero so it gives me the last day of the next month in this scenario i'll set the start date to the first day of the month and the end date as the last date of the current month next i will add a drop down control for the items property i will provided a standard array that has three values low medium and high so those are the three options that show up now if we look at the default property of the drop down control it's set to 1 the default value is closely tied into the schema of the items property that you provide for the drop-down control in my scenario the items property has 3 values low medium and high so if i would like to change the default value to let's say medium all i have to do is set default to the text medium and now the priority drop down control defaults to that specific value another common scenario is to default it to empty or to plug in a default value that says please select the first thing we need to do is set the allow empty selection property for that drop down control to true once we do that the user is able to open the drop down control and if they select the value that's already selected it will go to empty and now if i set the default property to an empty string it will set the default value of that drop down control to empty now to insert something like please select as the default value many a times we end up with adding that please select as an option in our items property of the drop down control and if you're reading this from a data source maybe a choice column in sharepoint or some table in excel sql database you would not want to insert a value in there that says please select so how do i get that as the default value of my priority drop down list now the trick way to achieve that is by inserting a label control right on top of the drop down control make sure that this label control is sitting behind the drop down control the text for this label control i will set it to please select now the label control has that text but it is not visible because the drop down control is sitting on top of it so for the drop down control we have a property called fill i will replace this with transparent now the moment i set the fill to transparent that label control that is sitting behind the drop down control is visible so the user sees that value which is please select now the user can open the drop down control and make a selection even though i've made that selection that label control which is please select is still visible so what we need to do here is for that label control which has the text please select i will set its visible property to is blank my drop down control dot selected dot value if you observe the value selected is medium so please select does not show up if i reselect this value my drop down is blank so that label control which is please select shows up next let's add a combobox control for the items property for this i will set it to an array of colors the user can make multiple selections if there is no selection it gives the text which is find items this text comes from a property called input text placeholder and i'm free to change this to any text of my choice in my case find colors if i would like to default this to a specific color or a set of colors i have a property called default selected items this is an array all i have to do here is provide the color value so blue is the default value that's selected if i would like to default it to blue and yellow i can simply add that in the default selected items array and those are the two values that are selected by default a combo box control can also be set to only allow single selections by setting its select multiple property to false i have set the items property to an array of department values as it's blank it shows no text and the user can simply make a single selection now when it's empty if i want to show the value select department there is another property called no selection text for a single select combo box control is what i would have to set if i want to show the value when it is empty and that's the text that shows up right here if i would like to default it to an actual value once again i will use the same property default selected items it would still be an array and i should be providing it only a single value i can provided multiple values but it will still default to only the first one purely because the combobox control is single select once the default values are set the user is free to make changes i've made changes to the values of these controls however i would like to reset them for that i will insert a button control i will call this reset and when the user selects this i can start resetting my controls now typically we reset these one by one i will use a function called reset and provide the name of that control if i need to reset the next control which is start date and that would reset that control as well and so and so forth however if i have a lot of controls this function could be quite large now i'll show you an easier way with which you can reset all of these controls in one go simply hold the ctrl key and select all the controls that you would like to reset go to the reset property of these controls and set it to a variable i will call this variable var reset data now this variable does not exist currently when reset is clicked i will set that variable which is var reset data to false and then i will set that same variable to true basically every time this button is clicked that variable will change state from false to true which would in turn trigger the reset of all of those controls that have that variable as the reset property so now if i click on reset all of my controls have reset to their original values i have a gallery here that shows task data from a sharepoint list and if i select a specific item it will take me to the form control and show all the data related to that specific item the user can also click on the plus icon to create a new task now here is where we will apply those same concepts of default values two different column types priority here is a combo box control which has four options and this is a single select combo box control so let's go and make a change to this i'll select the combo box control go to advanced and the first thing i would have to do is i would have to unlock the data card because in a form control every column that is added to the form control is locked and in order to make changes you have to unlock it so i will first unlock it i will head over to the input text placeholder property and change this to set priority so that's the empty value text placeholder that shows up now if i would like to default this let's say to start with medium priority when the user is creating a new item in my sharepoint list meaning the form is in new mode in that case for the data card i have the priority data card selected there is a property called default by default it is set to this item dot priority now here it is extremely important first note what is the type of this column in my sharepoint list priority in my sharepoint list is a choice column i have written a blog post that walks through the different column types in sharepoint and how you can set the values for those columns here we are dealing with a choice column so the way we will set its default value is as follows in order to set the default value the priority column to medium only when the user is creating a new item i will use the following function if i would like to first check the mode of the form the data card its parent is the form control i can leverage parent dot mode if that is equal to form mode dot new in that case set the default value of this choice column in the following format and my choice value in this case would be medium if the form is not in new mode meaning the form is either an edit mode or a view mode then you leverage the actual value coming from that item this is a new form the priority is set to the default value of the choice column which is medium the same technique is what i will apply to most of my other data cards the title i have to first unlock the card here i will use that same formula if the form is in new mode let's say i would like to default the title to new task else i will leverage the actual value in that column start date this i would like to default to today's date once again i will unlock the card head over to default if the form is in new mode then set it to today's date else leverage the value from that column and here we can apply all those date related concepts that i showcased earlier let's say the due date should be seven days from today so the default value for this data card would be as follows assigned to this is a person type column in my sharepoint list for a person type column the way we set its value is as follows so i'll simply copy this go back to the data card for assign to unlock the card go to its default property if the form is in new mode i will paste that code that i copied else i will get the value from that column here in case of new mode it is setting the default value to the current logged in user by leveraging the user function let's try the same thing with another person type column here called manager now the manager needs to be the current logged in users manager and to plug in the manager details all i need is the manager's email address and full name and to get that under data sources i can add a connection to office 365 users here to get the current logged in users manager and to keep the code clean i will use a function called with in here i'll create a scoped variable called manager i will use office 365 users dot manager v2 function i will pass the current logged in user's email address this will give me the details of the user's manager i'll replace this part with manager dot mail i'll use it here as well and for display name i will use manager dot display name and i will close the bracket for the width function if i look at the manager column default value it is actually picking my manager from active directory which is sarah i have a column called department this is a lookup column in my sharepoint list it looks up to a different list that i have called departments the way we set a lookup column is we need to provide its value and its id so let's say i would like to default the department to hr the value is hr and the id is 2. so for the department data card if i head over to the default function if the form is a new mode in that case i will set the value to hr the id for that is 2 else i will get the value from the column itself so here it has defaulted to my lookup column which is hr now let's take this one step further in my office 365 profile i have the department information for the user the department for reza is id the items property for this combo box control which loads all that lookup column information the function here is choices of my sharepoint list dot the name of the column and if you look at the tabular data that it provides it has the id and the value now all i need to do is get that record from this table where the value matches the department value coming from my active directory and for that i will copy this items property code go to my data card if the form is a new mode i will use the lookup function on the code that i copied which is choices of my sharepoint list dot the column name which is department my condition here is where the value is equal to office 365 users dot my profile v2 which is the current logged in users profile information dot department that's the ad property that is holding the department column value and here is the result and action the department column has defaulted to my department from active directory which is it and this is a lookup column category is a multi-select choice column for multi-select choice columns all i have to do is provide tabular data that has the following format which is a record that contains a value property that matches a specific value of the choices that are provided so here if i would like to default it to let's say design my formula is if the form is in new mode here i'll create a table the record is value design so now it defaults to that specific value if i want to default it to additional values let's say research as well it's a table so i can append research as well to this so now i have this form that is filled out with a lot of default values which of course the user can change and once the user hits submit that data would be recorded in my sharepoint list and i can go back to that same item this time the form is in edit mode and i am free to make changes to this another common case is to limit by default even the options that the user sees let's say when the form is in new mode so if the user is creating a new task the only options that i would like to provide to the user are not started and in progress the first two values in this choice column since i'm making changes i will unlock this data card for this combo box control inside this data card the items is being loaded by leveraging the choices function if the form is in new mode in that case i will use the first n function to load only the first two choices from my choices function else meaning if the form is in edit of view mode i will load all the choices here the form is a new mode so the only two options that are provided for the user are not started and in progress once i create this task and once i go back to this task to modify this this time the form is not in new mode if you look at the progress column it will show me all the options if you enjoyed this video then do like comment and subscribe to my youtube channel and thank you so much for watching
Info
Channel: Reza Dorrani
Views: 134,524
Rating: undefined out of 5
Keywords: powerapps, power apps, powerapps set default value, powerapps default current user, sharepoint, reza dorrani, combobox default selected items powerapps, powerapps default lookup field, powerapps default date, default, powerapps default combobox, powerapps set default value of dropdown, powerapps set default value for choice field, power apps set default value, today, power apps defaults, powerapps sharepoint default value, dropdown, date, lookup, choice, microsoft, powerapps default value
Id: bjvigaL68ts
Channel Id: undefined
Length: 22min 49sec (1369 seconds)
Published: Mon Jul 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.