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 / Button Formula Support
Power Apps
Answered

Button Formula Support

(0) ShareShare
ReportReport
Posted on by 16

Dear Team,

 

Question 1 - Cannot we add the patch function with If Function which replaces the Boolean with Patch

If(Value(SoldText.Text) < gblProduct.Stock, Patch(Hardware1,gblProduct,{SellingQuantity:CurrentStock.Text-SoldText.Text}),xxxx)

 

gblProduct is a variable

 

I have a  Sold button to textinput as mentioned in the image. If my Idealstock is 500, When user enter 600 in text box I need to neglect it, If user inputs below 500 and above 0 I need to save it in the data source also cannot go to -1,.....

 

I have used the below syntax to my restock also need to modify it because I get minus values, Need a limitation to user input.

 

Patch(Hardware1, gblProduct,{SellingQuantity:OrderQuantity.Text+CurrentStock.Text})

 

I'm a beginner for Powerapps and Kindly help me on this matter.

 

Thank you😁

appimg.PNG
Categories:
I have the same question (0)
  • BCLS776 Profile Picture
    8,994 Moderator on at

    If you are having problems with this statement, look closely at a few things to make sure they work properly:

    1. You mention gblProduct is a variable - is it a variable of "record" type, with a sub-field named "Stock" that is a number? If not, you will have a type mismatch in the condition of your If() statement
    2. Your If() statement triggers a behavior formula (the Patch), therefore, it must be located in a property that starts with "On", for example, OnSelect, OnVisible, etc.
    3. Your If() statement has a second condition "xxxx". That may only be a placeholder for this post, but make sure that is removed/edited from your code.

    Hope that helps,

    Bryan

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi @Bhashb11,

    Have you solved your problem?

    Do you want to patch based on the stock?

    Could you please share more details about the Idealstock and CurrentStock, is that the same?

     

    To achieve your need, please check as below.

    1). Question 1 - Cannot we add the patch function with If Function which replaces the Boolean with Patch

    Yes, you can. If the SellingQuantity is a Text column and gblProduct.Stock is a number data, please write the Patch() as below:

    If(Value(SoldText.Text) < gblProduct.Stock, Patch(Hardware1,gblProduct,{SellingQuantity:CurrentStock.Text-SoldText.Text}),xxxx)

    2). To validate the number input within the sold Text input box, you could set the OnChange property of it as below:

    If(
     Value(SoldText.Text) >= 0 && Value(SoldText.Text) < Value(Idealstock.Text),
     Patch(
     Hardware1,
     {Sold: SoldText.Text}
     ),// This helps you save the sold data when the sold input is less than the ideal stock
     Reset(SoldText) && Notify(
     "Please input a number less than the ideal stock",
     Error
     )//This helps neglect it when the sold input is more than the ideal stock
    )

    3). To avoid minus values, do you meant that the calculation between the OrderQuantity and CurrentStock? If so, you just need to write formula set for the Onselect property of a button as below:

    If(
     Value(OrderQuantity.Text+CurrentStock.Text)<0,
     Notify("Please note that you should have a positive number!",Error),
     Patch(Hardware1, gblProduct,{SellingQuantity:OrderQuantity.Text+CurrentStock.Text}
    )

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#2
11manish Profile Picture

11manish 192

#3
Valantis Profile Picture

Valantis 128

Last 30 days Overall leaderboard