cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
kpavlidis
Level: Powered On

Dropdown list and Default value that it is not included in the item variable

I have a dropdown list and i want to set that the default value when the formmode is new to a character like "-" and when the formmode is somethings else it will go with the 

 

ThisItem.VariableName

So if the dropdown list is named country then the function would have been.

 

If(SharePointForm1.Mode=FormMode.New,"-",ThisItem.country)

The Item variable is using a db table for countries.

 

So Item:

 

SortByColumns('[my_db].[country]',"country_name")

And Value is: country_name

 

I do not want to have a record in the DB for one country with country name as "-". If i do it it works properly but if i do not it has problem. 

 

Is there a way to add on the fly more values? The db table could be very big in general cause this goes for all dropdowns and db tables

 

 

tchin-nin
Level 10

Re: Dropdown list and Default value that it is not included in the item variable

Hi @kpavlidis

 

Depending how big is your country table (more than 500items?), You can store it to a local collection and add a "-" record. 

App.OnStart :

ClearCollect(CountriesCol, SortByColumns('[my_db].[country]',"country_name"),{country_name:"-"})

 The Items Property of your dropdown then should be : CountriesCol

Then use the default property like this 

LookUp(CountriesCol,country_name="-')

 

Théo

kpavlidis
Level: Powered On

Re: Dropdown list and Default value that it is not included in the item variable

Thank you i know this , and this is why i have said that the table is big and that this does not go only to one table.

 

I want to use this for customazation of list form and also these forms could have 5-6 dropdowns and some of them could be very big so it is not good for me to create collections when i can read from a db.

 

And solution of combo box does not work. When i try to save it does not update the values and when i add new records it does not save anything it gives empty data. I suppose that this has to do with the Datacard.Update variable that could be set only to Combobox1.Selected and  not the excact value cause it gives error. The error is that the property needs a record but the funtion returns text.

tchin-nin
Level 10

Re: Dropdown list and Default value that it is not included in the item variable

You can put whatever you want in your Update property of the DataCard as long as it is structured as DataSource expects. 

If your storing the country name into a Text column in SharePoint, then the Update Property should return text :

Combobox.Selected.country_name

 

Théo

KroonOfficeSol
Level 10

Re: Dropdown list and Default value that it is not included in the item variable

@kpavlidis

 

Your DB table surely has an CountryID stored and not a CountryName, is this correct?

 

This means the DataCard.Update attribute want to have an int returned. So you put in the combobox in the datacard, connect this to your table and return the int to the Update attribute. Formula's:

ComboBox.Items

SortByColumns(ShowColumns(YourCountryTable, "CountryName", "ID"), CountryName, Ascending)

DataCard.Update

ComboBox.SelectedItems.ID

Also do this:

Turn off the multiselect on the combobox!


And your done.

 

Btw, would you like to store the big tables in collections then use Flow. How to? See here: MS PowerApps | SQL Server & Flow

Hope this helps,

Paul

Community Support Team
Community Support Team

Re: Dropdown list and Default value that it is not included in the item variable

Hi @kpavlidis,

Which data source does your Edit form connect to? A SP list?

Which type is the Country column (within your Edit form) that you mentioned?

Do you custom a form for your SP list on your side?

Based on the formula that you provided, I suppose that you custom a form your SP list using PowerApps, is it true?

Do you want to set a default value within the Dropdown control within your Edit form (SharePointForm1)?

I have made a test on my side, I afraid that the Dropdown control could not achieve your needs. In other words, based on your needs, I afraid there is no way to set a default value within a Dropdown control.

As an alternative solution, I think the Combo Box control could achieve your needs. On your side, you could consider take a try to remove/delete the Dropdown control within the Country Data card, and then add a Combo Box control within it. Please check the following GIF screenshot for more details:

Test1.gif

On your side, set the Items property of the Combo Box control (ComboBox1) to following:

SortByColumns('[my_db].[country]',"country_name")

Set the Update property of the Country Data card (which contains above Combo Box control) to following:

ComboBox1.Selected.country_name

Set the DefaultSelectedItems property of the Combo Box control (ComboBox1) to following:

If(
    SharePointForm1.Mode=FormMode.New,
    {
     Value: "-"
    },
    {
      Value:  ThisItem.country
    }
)

The custom form works successfully as below:6.JPG

Note: The Department column is a Single line of text type column in my SP list.

 

Best regards,

Kris