cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Patch function updating the first record in the SQL table

Hi ,

 

I have a SQL table as follows - 

PayrollID | EmpID |   WeekOf  | Day1Hrs | Day2Hrs | Day3Hrs |.....| Day7Hrs | Submitted 

---------------------------------------------------------------------------------------------

 1            | 101      | 7/26/2020 |  8          |  8            |  8            |......| 8            | false

 2            | 102      | 7/26/2020 |  6          |  6            |  6            |......| 6            | false

 

To update the second record (EmpID = 102) I wrote the following Patch function - 

Patch('[dbo].[PayrollHours]', LookUp('[dbo].[PayrollHours]', PayrollID = PayrollDataNew[@PayrollID]),
{Day1Hrs:PayrollDataNew[@Day1Hrs], Day2Hrs:PayrollDataNew[@Day2Hrs], Day3Hrs:PayrollDataNew[@Day3Hrs], ......., Day7Hrs:PayrollDataNew[@Day7Hrs], Submitted:PayrollDataNew[@Submitted]})

 

Note : 

PayrollDataNew Collection - 

PayrollID | EmpID |   WeekOf  | Day1Hrs | Day2Hrs | Day3Hrs |.....| Day7Hrs | Submitted 

---------------------------------------------------------------------------------------------

 2            | 102      | 7/26/2020 |  7          |  7            |  6            |......| 6            | true

 

========Desired Result in SQL==============

PayrollID | EmpID |   WeekOf  | Day1Hrs | Day2Hrs | Day3Hrs |.....| Day7Hrs | Submitted 

---------------------------------------------------------------------------------------------

 1            | 101      | 7/26/2020 |  8          |  8            |  8            |......| 8            | false

 2            | 102      | 7/26/2020 |  7          |  7            |  6            |......| 6            | true

====================================

 

=========Actual Result in SQL===============

PayrollID | EmpID |   WeekOf  | Day1Hrs | Day2Hrs | Day3Hrs |.....| Day7Hrs | Submitted 

---------------------------------------------------------------------------------------------

 1            | 101      | 7/26/2020 |  7          |  7            |  6            |......| 6            | true

 2            | 102      | 7/26/2020 |  6          |  6            |  6            |......| 6            | false

========================================

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

@WarrenBelz 

Thank you for your inputs, but the issue was in the Lookup function -

Patch('[dbo].[PayrollHours]', LookUp('[dbo].[PayrollHours]', PayrollID = PayrollDataNew[@PayrollID]),
{Day1Hrs:PayrollDataNew[@Day1Hrs], Day2Hrs:PayrollDataNew[@Day2Hrs], Day3Hrs:PayrollDataNew[@Day3Hrs], ......., Day7Hrs:PayrollDataNew[@Day7Hrs], Submitted:PayrollDataNew[@Submitted]})

 

PayrollDataNew[@PayrollID]) was not returning integer data type, so after I added Value() function it worked -

Patch('[dbo].[PayrollHours]', LookUp('[dbo].[PayrollHours]', PayrollID = Value(PayrollDataNew[@PayrollID])),
{Day1Hrs:PayrollDataNew[@Day1Hrs], Day2Hrs:PayrollDataNew[@Day2Hrs], Day3Hrs:PayrollDataNew[@Day3Hrs], ......., Day7Hrs:PayrollDataNew[@Day7Hrs], Submitted:PayrollDataNew[@Submitted]})

View solution in original post

9 REPLIES 9
Highlighted
Super User III
Super User III

Hi @MJK ,

Firstly you have a reference to PayrollHoursID instead of PayrollID, but to avoid the ambiguity try this

ForAll(
   PayrollDataNew As NewData,
   Patch(
      '[dbo].[PayrollHours]', 
      {PayrollId:NewData.PayrollId},
      {
         Day1Hrs:NewData.Day1Hrs, 
         Day2Hrs:NewData.Day2Hrs, 
         Day3Hrs:NewData.Day3Hrs, ......., 
         Day7Hrs:NewData.Day7Hrs, 
         Submitted:NewData.Submitted
      }
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted

@WarrenBelz 

"Firstly you have a reference to PayrollHoursID instead of PayrollID, but to avoid the ambiguity try this" 

- Thats a mistake, I corrected it in my post

Highlighted

@MJK ,

OK I see you have done that now, but the rest of the post is relevant to try to get the right record to update.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted

@WarrenBelz ,

 

The above code gives an error - 

The function has some invalid arguments. 

Highlighted

@MJK ,

The syntax is valid (see below - this is a collection from the destination list and works perfectly).

PatchAs.png

Please have a look at your field and control values - start with this

ForAll(
   PayrollDataNew As NewData,
   Patch(
      '[dbo].[PayrollHours]', 
      {PayrollId:NewData.PayrollId},
      {
      }
   )
)

and if valid, add the fields in one at a time until you find the error.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted

Hi @MJK ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted

@WarrenBelz 

Thank you for your inputs, but the issue was in the Lookup function -

Patch('[dbo].[PayrollHours]', LookUp('[dbo].[PayrollHours]', PayrollID = PayrollDataNew[@PayrollID]),
{Day1Hrs:PayrollDataNew[@Day1Hrs], Day2Hrs:PayrollDataNew[@Day2Hrs], Day3Hrs:PayrollDataNew[@Day3Hrs], ......., Day7Hrs:PayrollDataNew[@Day7Hrs], Submitted:PayrollDataNew[@Submitted]})

 

PayrollDataNew[@PayrollID]) was not returning integer data type, so after I added Value() function it worked -

Patch('[dbo].[PayrollHours]', LookUp('[dbo].[PayrollHours]', PayrollID = Value(PayrollDataNew[@PayrollID])),
{Day1Hrs:PayrollDataNew[@Day1Hrs], Day2Hrs:PayrollDataNew[@Day2Hrs], Day3Hrs:PayrollDataNew[@Day3Hrs], ......., Day7Hrs:PayrollDataNew[@Day7Hrs], Submitted:PayrollDataNew[@Submitted]})

View solution in original post

Highlighted

@MJK ,

So you were storing a numeric value as Text? Not something usual and was certainly not evident from your post.

As you can understand, I can only advise on the information provided.

Highlighted

Yes sure I understand.

 

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 (13,957)