Reputation: 129
I am trying to learn power apps. I am using a form from where I am trying to update new stock quantity in the sharepoint list. My form is -
The user will enter the quantity and upon successful submission of the form the new stock quantity should reflect in the sharepoint list. New stock qty = stockqty - qty entered by the user.
I am trying to write a formula but don't know where it is going wrong. . I am currently storing my new Stock Quantity in a label. Blue Arrow is label3( new stock Qty) and Red arrow is Label4(product Id).
This code is on editForm onSuccess event-
Patch(
Products,
First(
Filter(
Products,
ThisRecord.ID = Value(Label4.Text)
)
),
{StockQty: Value(Label3.Text)}
);
Navigate(Scr_WelcomePage);
ResetForm(Form1);
This is the formula for label3-
This is onSubmit button event-
SubmitForm(Form1);
ResetForm(Form1);
The issue is that my patch function is unable to update the updated value of stockQty in the sharepoint list. I tested my formula by hard coding the values. It worked and updated the values.
Patch(Products,First(Filter(Products, ThisRecord.ID =2),
{StockQty: 4});
I then hardcoded the StockQty value and read Product ID from Label4, it also worked. It seems that the formula is unable to read the value of new stock Qty from label3. I double checked my Quantity card value from the edit form. It is DataCardValue14. I dont know what I am missing.
I tried to debug by monitoring the app. It gave me this - Value function converted an empty text to a blank value. Is this the issue? What should I do to remove it.
Update: Tried with the Lookup Function but same problem persists.
Patch(
Products,
LookUp(
Products,
ID = Value(Label4.Text)
),
{StockQty: Value(Label3.Text)}
);
Navigate(Scr_WelcomePage);
ResetForm(Form1);
This was my input-
Here are the screenshots of the Monitor.
Upvotes: 0
Views: 2309
Reputation: 50
I think the issue might be what you call your 'onSubmit button event'. You are resetting the form two different places. Your onSuccess event first uses the two label values, which reference current values from Form DataCards, and then it resets the form. I think that is fine. But, you then say:
This is onSubmit button event-
SubmitForm(Form1);
ResetForm(Form1);
First, I am not aware of anywhere actually called onSubmit. I assume you mean the onSelect event for the button that you are using as your Submit button. If that is the case, then you are resetting the form in that button's onSelect event AS WELL AS in the form's onSuccess event. I would guess that you simply have a race condition where the onSuccess event is triggerred essentially in parallel with the second step of your Submit button's onSelect event. That would explain why hard coding things makes it work.
Also, you are using ThisRecord correctly. Inside a Filter() function, ThisRecord refers to the current item being filtered. ThisItem would be incorrect since that is used to refer to the current item in a Gallery or similar (and maybe a form, I forget).
Upvotes: 0
Reputation: 981
I think your Patch formula is not entirely correct. Instead of ThisItem.ID
, you should use simply ID
.
Patch(
Products,
First(
Filter(
Products,
ID = Value(Label4.Text)
)
),
{StockQty: Value(Label3.Text)});
If I guess correctly, by using ThisItem.ID = Value(Label4.Text)
you created a condition that could always be true. Your test patch was successful, because it evaluated true for all existing records and you updated the first one. Seemingly the lookup worked, but this is a false positive result.
Upvotes: 0