cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AVTS
Super User
Super User

Collection to Dataverse Table

Dear Friends,

 

While copying the collection data to Dataverse table i am getting following error, 

 

Below is formula,  Collection is pmosave2 and table is EsmMOtimes

 

ForAll(pmosave2 As currentRecord1,
With({rowCount1: CountRows(Filter(pmosave2,HTTP_Body=currentRecord1.HTTP_Body))},

If(rowCount1 = 1,
EsmMOtimes(
currentRecord1.HTTP_Body,
currentRecord1.HTTP_Body_1,
currentRecord1.HTTP_Body_2,
currentRecord1.HTTP_Body_3,
currentRecord1.HTTP_Body_4,
currentRecord1.HTTP_Body_5,
currentRecord1.HTTP_Body_6

)
)
)
);

 

Above coding is not responding as expected. Is there anything wrong with this coding . Please share your expertise. 

 

Thanks in Advance, 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AVTS
Super User
Super User

ForAll(pmosave2 As currentRecord,
With({rowCount: CountRows(Filter(pmosave2,HTTP_Body=currentRecord.HTTP_Body))},

If(rowCount = 1,
Patch(EsmMOtimes,
Defaults(EsmMOtimes),
{
HTTP_Body: currentRecord.HTTP_Body,
HTTP_Body_1: currentRecord.HTTP_Body_1,
HTTP_Body_2:currentRecord.HTTP_Body_2,
HTTP_Body_3:currentRecord.HTTP_Body_3,
HTTP_Body_4:currentRecord.HTTP_Body_4,
HTTP_Body_5:currentRecord.HTTP_Body_5,
HTTP_Body_6:currentRecord.HTTP_Body_6
}
)
)
)
);

 

View solution in original post

17 REPLIES 17
AVTS
Super User
Super User

ForAll(pmosave2 As currentRecord,
With({rowCount: CountRows(Filter(pmosave2,HTTP_Body=currentRecord.HTTP_Body))},

If(rowCount = 1,
Patch(EsmMOtimes,
Defaults(EsmMOtimes),
{
HTTP_Body: currentRecord.HTTP_Body,
HTTP_Body_1: currentRecord.HTTP_Body_1,
HTTP_Body_2:currentRecord.HTTP_Body_2,
HTTP_Body_3:currentRecord.HTTP_Body_3,
HTTP_Body_4:currentRecord.HTTP_Body_4,
HTTP_Body_5:currentRecord.HTTP_Body_5,
HTTP_Body_6:currentRecord.HTTP_Body_6
}
)
)
)
);

 

RandyHayes
Super User
Super User

@AVTS 

This formula is not going to work!

 

First - What, and why, are you doing a count rows on the same collection and then trying to work on that record if it exists??  Of course it would exist, otherwise it would not be in the table.  Are you doing this because you could have more than one and you only want to perform this action on instances where there is only one record and not a second or more?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
RandyHayes
Super User
Super User

@AVTS 

Your formula is using the ForAll backward.  It is not a For Loop.  It is a function that returns a table.  Your performance will suffer greatly when using it backward like that.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi @RandyHayes  Thanks for taking time to respond on my query. Much Appreciated.

 

Requirement 1 . 

 

Copy the data from collection to Dataverse Table 

 

Collection name : pmosave2

Table name : EsmMOtimes

 

Both places column name is same. 

 

Requirement 2 : 

 

I wanted to exclude the records during the copy from collection to table if that is available more than one.

 

So - if the HTTP_Body value appears only once in the source, then it will run the button program for that row - otherwise if it appears more than once, it will not run the button program

 

 

So my coding fulfills both requirement. 

 

Please share your idea of your working which can over come the application performance / Simplify the process. 

 

Thanks in Advance, 

RandyHayes
Super User
Super User

@AVTS 

If the column names are identical to the source, then the following will give you that functionality in a more performant way:

Patch(EsmMOtimes,
    ForAll(        
        Filter(
            AddColumns(
                GroupBy(pmosave2,
                    "HTTP_Body", "_data"
                ),
                "_rows", CountRows(_data)
            ),
            _rows=1
        ) As _item,
        LookUp(pmosave2, HTTP_Body = _item.HTTP_Body)
    )
)

This will (internally) create a table of records where the count of HTTP_Body is only found once.  Then it returns (from the ForAll) a table of records from looking up each record in the collection based on the unique HTTP_Body.

Then that entire table is handed to Patch to actually do the patch to the datasource.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you @RandyHayes i am getting following error  . Is this something to do with sequencing . Please assist. 

 

AVTS_0-1658328237888.png

AVTS_1-1658328273553.png

 

Thanks in Advance 

 

@RandyHayes  please check this error when you have time. Looks very interesting , Thanks in Advance

RandyHayes
Super User
Super User

@AVTS 

This means that you have a column name or data type in your collection that does not match the data source.

You will need to look at how you are defining and putting records into your collection.  The column names need to match the real names of the columns and the data types in the columns in your records needs to match the data types for the columns in the datasource.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

All are identical . Below is the code details. Let me know if my understanding is incorrect. 

 

 

Collection Formula..

 

ForAll(
Gallery2.AllItems,
Collect(
colLocalAnswers111,
{

maintenanceOrder : Label9_2.Text,
storageLocation :ThisRecord.storageLocation,
materialNumber: ThisRecord.materialNumber,
//or whatever the control's name is
quantity: TextInput9.Text

}
)
);

 

----

Table view 

AVTS_1-1658428186562.png

 

 

Datatable Collectionview,

AVTS_0-1658428114891.png

 

 

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (1,567)