cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Create new records in CDS entity based on each unique record from another datasource

Hi,

 

I have posted a similar issue before but I have now changed the scenario that I am trying to achieve.

 

I have the following entities:

QAOrderHeader - Fields are as follows: | OrderID | Description | 

QAOrderLines - Fields are as follows: | Line number | Test | OrderID | Result |

QATests - Fields are as follows: | Test | Test type | 

 

I need to automatically create records in QAOrderLines when selecting an existing QAOrderHeader record from a gallery. The records that need to be created in QAOrderlines should be one record for each record from the QATests table. There is a field called "Tests" in QAOrderLines which should be populated with a unique test from the QATests table. I.e First record created in QAOrderLines takes the first Test from QATests, Second QAOrderLines record takes the second Test from QATests and so on.

 

Screen 1 (List of existing order headers):

QAHeaders.PNG

 

When I press the next arrow on a record it takes me to Screen 2 where I have a collection based where records are created for all tests in the QAtests table:

QALines.PNG

 

As you can see I have achieved the Line number, OrderID and Result fields outputs that I needed. The only thing that isnt working is the test field. Each record should be the next test record from the QAtests table but instead it duplicates the first record. I am aware this is because I am using "First" function in my code currently but I have tried not using "First" and it puts all tests into each record.

 

Here is my code from selecting in Screen 1:

 

Select(Parent);

ForAll(

    QATests,

    Collect(

        testcollection,

        {

            Name: Gallery1.Selected.'Quality order',

            Test: First(QATests.Test),

            Result: "Blank"

        }

    )

);

ForAll(

    testcollection,

    Collect(

        rownumber,

        Last(

            FirstN(

                AddColumns(

                    testcollection,

                    "RowNumber",

                    CountRows(rownumber) + 1

                ),

                CountRows(rownumber) + 1

            )

        )

    )

);

Navigate(

    Screen2,

    None

)

 

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Frequent Visitor

Re: Create new records in CDS entity based on each unique record from another datasource

Hi,

I have now resolved the issue by taking a slightly different approach to this.

I brought the QATests.Test into a collection and then used a new collection to add the "Results" field and "Order ID" field to the initial collection. This gives me the result I am looking for except the line number. The ForAll function when adding the line number seems to mess up the way the "Test" field works and it reverts back to bringing the same Test in for all records. I will work around this by having the line number auto generate in the CDS entity when I patch back.

Screen 1:

QAHeaders.PNG

Code on the next arrow:

Select(Parent);
ClearCollect(
    coltests,
    QATests.Test
);
ClearCollect(
    colorderlines,
    AddColumns(
        coltests,
        "Results",
        "Blank",
        "OrderID",
        Gallery1.Selected.'Quality order'
    )
);
Navigate(
    Screen2,
    None
)

This gives me the following results on screen 2:

QALines.PNG

 

Thanks

View solution in original post

1 REPLY 1
Highlighted
Frequent Visitor

Re: Create new records in CDS entity based on each unique record from another datasource

Hi,

I have now resolved the issue by taking a slightly different approach to this.

I brought the QATests.Test into a collection and then used a new collection to add the "Results" field and "Order ID" field to the initial collection. This gives me the result I am looking for except the line number. The ForAll function when adding the line number seems to mess up the way the "Test" field works and it reverts back to bringing the same Test in for all records. I will work around this by having the line number auto generate in the CDS entity when I patch back.

Screen 1:

QAHeaders.PNG

Code on the next arrow:

Select(Parent);
ClearCollect(
    coltests,
    QATests.Test
);
ClearCollect(
    colorderlines,
    AddColumns(
        coltests,
        "Results",
        "Blank",
        "OrderID",
        Gallery1.Selected.'Quality order'
    )
);
Navigate(
    Screen2,
    None
)

This gives me the following results on screen 2:

QALines.PNG

 

Thanks

View solution in original post

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (7,285)