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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to set a field's v...
Power Apps
Answered

How to set a field's value on the push of a button

(1) ShareShare
ReportReport
Posted on by 2,914

As per title, I want to set a field's value (a datacard in a form) to a value I have calculated on the push of a button.

 

Scenario:

This is an app for taking menu orders. First, the OrderHeader is populated (Cust Name, time, discount, amount paid).

 

Next, the OrderDetail is populated (Menu Item, Quantity, OrderHeaderID).

 

Finally, when the customer is ready to pay, we open OrderHeader again in Edit mode. The screen allows for a discount to be selected. A label on the screen has a formula which calculates the total of the OrderDetail for the selected customer less any discount.

 

I want the user to be able to accept the calculated amount by clicking a button or type in a value manually if, for some reason, the amount paid does not match the calculated amount.

 

I have all this working except populating the field's value by clicking the button. Can anyone give me a hint how to proceed?

 

Cheers

Paul

Categories:
I have the same question (0)
  • CarlosFigueira Profile Picture
    on at

    You can have a variable that specifies the discount (in percentage) to be applied to the total that is initialized to 0 when the form first appears (e.g., in the screen's OnVisible property). In the "apply discount" button, you can set the value of the discount variable to whatever discount you want to give. Then you can have the Default property of the input text control within data card to use that variable. Something along the lines of the following properties below:

    OrderHeaderScreen.OnVisible: UpdateContext({discount:0})
    ApplyDiscountButton.OnSelect: UpdateContext({discount:Value(DiscountTextInput.Text)})
    DataCardValueOrderTotal.Default: Text(calculatedTotal * (1 - discount / 100))

    Where 'calculatedTotal' is the value that you already have that contains the current total, and 'DiscountTextInput' is a control where the user will enter the discount amount (if the discount is entered in another way you'll need to change that).

     

    When the button is selected, the value of the 'discount' variable will be changed (assuming that the discount is different than 0), so the default value of the text input that holds the order total will be updated - but it will still be editable by the user if they want to do so.

  • PaulD1 Profile Picture
    2,914 on at

    Thanks @CarlosFigueira 

     

    As per the workflow, the Amount Paid is populated as zero when the record is initially created. It is later when we edit the record that I want the press-able button. Your code is setting the Default property, but we already have a value in the field, so presumably, this will have no effect?

     

  • Verified answer
    CarlosFigueira Profile Picture
    on at

    If there is already a value in the field, what is the current value for the Default property of the text input? If it's something like Parent.Default, then you can set it to

    Parent.Default * (1 - discount / 100)

    Notice that the discount will be 0 originally, so it will be equivalent to Parent.Default. Only when the value of the 'discount' variable is changed (by pressing that button) that the default value will change, which will cause the value shown in the text input to be updated.

  • PaulD1 Profile Picture
    2,914 on at

    Thanks @CarlosFigueira

     

    Finally got back to this requirement and your tips got me there. What I needed was: to see the value already recorded for the amount paid,

    * In the PAID box, see the value already paid

    * Have a PAY IN FULL button that changes the value of the PAID box to the AMOUNT DUE (already calculated in a control on the screen)

     

    What I did was to set the DEFAULT of the PAID box to a variable as suggested. When the form opens (IsVisible) populate the variable with the current PAID value. When the PAY IN FULL button is pressed, the value of the variable is set to the AMOUNT DUE.

     

    Seems a bit convoluted just to set a text box's value, but seems to be working for now - thanks!

  • MK1 Profile Picture
    169 on at

    Hi

    In my scenario,

    When we try to submit a new request to Add and Remove User.

    I have two buttons, Add and Remove on my edit screen.

    When we click on Add button ABC datacardvalue should be null.

    when we click on Remove button ABC datacardvalue should be "Remove".

    And the Datacardvalue should set to null once the form is submitted.

    Any ideas how to fix this would help.

     

    Thanks,

    Mk

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard