cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver I
Resolver I

Repeating Table Dropdown Write to correct CDS Fields

Hi there,

 

I am using CDS as a data source. Within the CDS I have created and entity called Environment Data several fields for waste quantities (see below). 

 

In my app, I have created a repeating table that uses a gallery and a collection. The repeating table includes a dropdown list that reads options from a CDS field (see attached). This part seems to work perfectly.

 

The issue I'm having is:

How do I write the entered data back to the correct CDS field based on the dropdown selected. For example, if the user selects Cardboard Recycling from the dropdown and enters 55 into the data entry box, how do i get it to write that number back to the ENV Cardboard Recycling Field in the CDS?

I think i need to use the patch function, but do i also need to do a big lot of 'IF' statement? is there another way?

 

Really appreciate any help!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Hi @Cym ,

I think I misunderstood you before.

Do you want to create a new record of CDS by using the data of site drop down,reporting date datepicker and all the data in the gallery?

For example, if you choose field1 in the first item, fill in data:"a";choose field2 in the first item, fill in data:"b".

Then the record that you want to update is like:

{site: site drop down.Selected.Value,reporting date:datepicker.SelectedDate,field1:"a",field2,"b"}

If so, please try this:

1)set the screen's OnVisible:

ClearCollect(collection,{field1:Value(""),field2:Value(""),field3:Value(""),....})

2)set the "+" icon inside the gallery OnSelect:

If("field1"=Dropdown1.Selected.Value,Patch(collection,First(collection),{field1:Value(TextInput1.Text)}),"field2"=Dropdown1.Selected.Value,Patch(collection,First(collection),{field2:Value(TextInput1.Text)}),"field3"=Dropdown3.Selected.Value,Patch(collection,First(collection),{field3:Value(TextInput1.Text),....})

//create a collection with the value of field1,field2,field3,...

3)set the submit button's OnSelect:

Collect(entity name,AddColumns(collection,"site",sitedrop down.Selected.Value,"reporting date",datepicker1.SelectedDate))

 //shape the collection with the value of site and reporting date, update with this shaped table.

 

2183.PNG

 Do not forget to replace with your fields name, entity name.

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
Highlighted
Community Support
Community Support

Hi @Cym ,

Do you want to use a drop down to choose field name and use a textinput to enter data to update?

Since you can not use fieldname as variable in Patch function, you could only use a specific fieldname in the patch function.

I'm afraid there's no better way then using Patch and If statement.

 

Try this formule(set the add button's OnSelect):

If(
drop down1.Selected.Value="Cardboard Recycling",Patch(entityname,ThisItem,{ENV Cardboard Recycling: Value(Textinput1.Text)}),
drop down1.Selected.Value="field2 name",Patch(entityname,ThisItem,{field2 name: Value(Textinput1.Text)}),
drop down1.Selected.Value="...",Patch(entityname,ThisItem,{...: Value(Textinput1.Text)}),
.....
)

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted

Hi @v-yutliu-msft 

 

Thanks for your response. Yes i do want to use the dropdown to choose the field name and use text input to enter the data. 

I have tried what you  are suggesting, but it doesn't seem to work with the collection? Have attached what i put in as a test but i get lots of errors. Maybe this is a bad idea - is there a better way to achieve the same outcome?  

 

C

Highlighted

Hi @Cym ,

Could you show me more details about your app?

I notice that your formula is not only about If and Patch function.

Your formula looks like:

ForAll(collection,Patch(data source,Defaults(...),

If(....,Patch(data source,ThisItem,{...})

I could not find the relationship between the first line and the second line.

Please show me the completed formula.

 

Best regards, 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted

Hi @v-yutliu-msft 

 

I have a button that creates a new collection (see attached). The issue i am having is that i am trying to write the information from the collection back to the data source in the CDS. The drop down list has the same fields as the CDS.

Highlighted

Hi @Cym ,

I think I understand your meaning.

Do you want to save the selected data in a collection and then compare data with the collection?

I think you do not need to use collection.

You could compare data with the drop down's selected value directly, no need to use ForAll,patch function.

Please just set the submit button's OnSelect like this:

If(
drop down1.Selected.Value="Cardboard Recycling",Patch(entityname,ThisItem,{ENV Cardboard Recycling: Value(Textinput1.Text)}),
drop down1.Selected.Value="field2 name",Patch(entityname,ThisItem,{field2 name: Value(Textinput1.Text)}),
drop down1.Selected.Value="...",Patch(entityname,ThisItem,{...: Value(Textinput1.Text)}),
.....
)

//please replace with your fields name.

To sum up, it's not supported to use variable as fieldname in patch function. You could only list them by using if statements one by one.

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted

Hi 

Highlighted

Hi @v-yutliu-msft ,

 

Thanks so much for persisting with me!  The problem I have with the solution that you have proposed is that the repeating rows will not work without creating a collection. Is there another way of creating the repeating rows with a drop down that can still be written back to the correct CDS fields?  

 

Cheers,

 

C

Highlighted

Hi @Cym ,

I think I misunderstood you before.

Do you want to create a new record of CDS by using the data of site drop down,reporting date datepicker and all the data in the gallery?

For example, if you choose field1 in the first item, fill in data:"a";choose field2 in the first item, fill in data:"b".

Then the record that you want to update is like:

{site: site drop down.Selected.Value,reporting date:datepicker.SelectedDate,field1:"a",field2,"b"}

If so, please try this:

1)set the screen's OnVisible:

ClearCollect(collection,{field1:Value(""),field2:Value(""),field3:Value(""),....})

2)set the "+" icon inside the gallery OnSelect:

If("field1"=Dropdown1.Selected.Value,Patch(collection,First(collection),{field1:Value(TextInput1.Text)}),"field2"=Dropdown1.Selected.Value,Patch(collection,First(collection),{field2:Value(TextInput1.Text)}),"field3"=Dropdown3.Selected.Value,Patch(collection,First(collection),{field3:Value(TextInput1.Text),....})

//create a collection with the value of field1,field2,field3,...

3)set the submit button's OnSelect:

Collect(entity name,AddColumns(collection,"site",sitedrop down.Selected.Value,"reporting date",datepicker1.SelectedDate))

 //shape the collection with the value of site and reporting date, update with this shaped table.

 

2183.PNG

 Do not forget to replace with your fields name, entity name.

 

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,371)