Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Patch code correction for stock posting

(0) ShareShare
ReportReport
Posted on by

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

 

 

 

 

  • MIA27 Profile Picture
    on at
    Re: Patch code correction for stock posting

    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)}
          )
       )
    );


  • MIA27 Profile Picture
    on at
    Re: Patch code correction for stock posting

    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

     

     

     

     

     

  • Verified answer
    WarrenBelz Profile Picture
    146,708 Most Valuable Professional on at
    Re: Patch code correction for stock posting

    @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
    on at
    Re: Patch code correction for stock posting

    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.

  • MIA27 Profile Picture
    on at
    Re: Patch code correction for stock posting

    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

     

  • Verified answer
    WarrenBelz Profile Picture
    146,708 Most Valuable Professional on at
    Re: Patch code correction for stock posting

    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

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,708 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,030 Most Valuable Professional

Leaderboard