0

I have a form in which I have 3 fields.

A text value: request

A number: number

And a choice that maps to a Dataverse choice: methods

When the user saves, I want to produce number times selected method records.

so for example, if users save:

request: ABC

number: 2

methods: M1, M2, M3

I want to save these rows in dataverse:

ABC,1,M1

ABC,1,M2

ABC,1,M3

ABC,2,M1

ABC,2,M2

ABC,2,M3

How do I populate records to Dataverse based on the number user enters?

I'm new to power apps and wondering what's the best way to do it? So far I successfully bind the choice to the Combo box and I can save one record at a time. Do I use a collection to save multiple records? Or would you rather use a Flow and a loop?

I'll really appreciate it if someone can tell me the best practice in this case.

Thanks

Ova

1 Answer 1

1

You dont need to make a collection or use a flow. You can basically do a loop in Power Apps and create the records in that loop.

Based on your input here is a loop that for each method chosen by the end user will create a record in dataverse after they click the save button.

On screen visible create a collection that you use for the numbers dropdown (use the col_loops.dropdownvalue in the items of the dropdown):

ClearCollect(col_loops, {dropdownvalue: 1, loopvalue: [1]}, {dropdownvalue: 2, loopvalue: [1,2]}, {dropdownvalue: 3, loopvalue: [1,2,3]} )

On the save button insert this formula, it will loop over the numbers selected and for each number also loop over the methods selected.

ClearCollect(
    current_loop,
    {curloop: 0}
);
ForAll(
    LookUp(
        col_loops,
        Value(Dropdown1.SelectedText.dropdownvalue) = dropdownvalue
    ).loopvalue,
    Patch(
        First(current_loop),
        {
            curloop: LookUp(
                current_loop,
                curloop <> "dummy"
            ).curloop + 1
        }
    );
    ForAll(
        ComboBox1.SelectedItems.Value,
        Patch(
            testtable01S,
            Defaults(testtable01S),
            {
                textcol: TextInput1.Text,
                numbercol: 3,
                choicescol: ThisRecord.Value
            }
        )
    )
)

In the power app there are just 3 fields, a simple text input for the request, a dropdown for the number and a combobox for the methods. The items in the combobox binds to the choice field in dataverse (like you have done).

I tested on my end, and in the above scenario i get 6 records created in dataverse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.