web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch code correction ...
Power Apps
Answered

Patch code correction for stock posting

(0) ShareShare
ReportReport
Posted on by 2

I am using power app for teams.

Want to update the stockQty of the table as according to for the user item selected in gallery based on PartNumber.

 

Below is the code which I am using to posting the stockQty of a table, beyond the correct column name it is giving an error.

 

Could not understand the mistake. Please guide to the correction

 

 

ForAll(
RenameColumns(GalleryCartOrder.AllItems,"PartNumber","cartedPartNumber"),
Patch(PartsIDtable, LookUp(PartsIDtable,PartNumber=cartedPartNumber),
{
    StockQty:StockQty-Value(CartQty.Value)
}
)
)

 

 

MIA27_0-1714195482934.png

 

 

below is the table name and column name which i am trying to use

 

MIA27_1-1714195668457.png

 

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

 

Later I tried below method also which Also has error :

 

ForAll(
  GalleryCartOrder.AllItems,
  With({_record:LookUp(PartsIDtable, PartNumber=ThisRecord.PartNumber)},
    Patch(
      PartsIDtable,
      _record,
      {
        StockQty: StockQty-Value(CartQty.Value)
      }
    )
  )
)
 
MIA27_0-1714197480354.png

 

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    155,623 Most Valuable Professional on at

    Hi @MIA27 ,

    Try this

    ForAll(
     GalleryCartOrder.AllItems As _Data,
     With(
     {
     _Record:
     LookUp(
     PartsIDtable,
     PartNumber = _Data.cartedPartNumber
     )
     },
     Patch(
     PartsIDtable,
     _Record,
     {StockQty: _Record.StockQty - Value(_Data.CartQty.Value)
     )
     )
    )

    If that does not work, what does the error say (it seems to be based on PartsIDtable - are you sure it is not PartsIDTable ?)

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • MIA27 Profile Picture
    2 on at

    The reference of the table is correct, I mean the table name, I rechecked its is correct in the code.

    I tried to apply the code and got the below error:

    MIA27_0-1714201249163.png

     

    Then tried to correct the code for which I have mentioned the  reason below, Pls. refer to my first post, where I have rename the columns to avoid conflict:

    ForAll(
       GalleryCartOrder.AllItems As _Data,
       With(
          {
             _Record:
             LookUp(
                PartsIDtable,
                PartNumber = _Data.PartNumber //In earlier code renamed the Column, actual was PartNumber,so changed  _Data.cartedPartNumber
             )
          },
          _Record,
          {StockQty: _Record.StockQty - Value(CartQty.Value) //this field was not from gallery, it was a screen text field, so changed _Data.CartQty
       )
    )

     

    Still the same error as shown below:

    MIA27_1-1714201707830.png

     

     

    Please guide

     

  • MIA27 Profile Picture
    2 on at

    The below is just your for your reference to your query for name and its error.

     

    But in my earlier reply, kindly find my test result on your advised code,

     

    Also please find the screen shot of the previous applied code, in the below image you can note the table name

     

     

    MIA27_2-1714202155213.png

    Both the error which I keep mouse on the table name gives as below 

     

    MIA27_3-1714202226372.png

     and if I keep on the below inside the patch on the table name its below error

    MIA27_4-1714202280266.png

     

    Confused why it is not picking the table name , what it is expecting.

     

    But strange, if i keep the Lookup field alone, like below no error:

    MIA27_0-1714202471496.png

    This proves that with method with lookup has some issue

     

    pls. guide, As I need to understand and then apply the stock updating code.

  • Verified answer
    WarrenBelz Profile Picture
    155,623 Most Valuable Professional on at

    @MIA27 ,

    Firstly, I amended the code a little while after I initially posted - please see the amended item, however I think the problem is elsewhere.

    You do not need to rename the column - your can specify it with either ThisRecord.PartNumber or use the As operator where I have used _Data as the identifier. I am a little confused as to why CartQty is not in the gallery as you would be deducting the same amount off every record. The problem here is that the structure is correct and you should not be getting errors if all your references are posted correctly.

  • MIA27 Profile Picture
    2 on at

    I am testing the code, will post result soon.

    In the mean time, I wanted to inform you (as shown in image), on the right side of the gallery is selected items, where I added a text field (blue background), so against each item after selection, user can change the required quantity, else it will remain 1. This field can be referred directly by its name while patching. So I mentioned    Value(CartQty.Value)

     

     

    MIA27_0-1714208199327.png

     

     

     

     

     

  • MIA27 Profile Picture
    2 on at

    Sir,

    After a small of adding change it worked. Thank you so much. 

    Below is the final code which worked

     

    ForAll(
       GalleryCartOrder.AllItems As _Data,
       With(
          {
             _Record:
             LookUp(
                PartsIDtable,
                PartNumber = _Data.PartNumber
             )
          },
          Patch(
             PartsIDtable,
             _Record,
             {StockQty: _Record.StockQty - Value(_Data.CartQty.Value)}
          )
       )
    );


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 413

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
timl Profile Picture

timl 315 Super User 2026 Season 1

Last 30 days Overall leaderboard