cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MikeWJS
Helper II
Helper II

Increment a Sharepoint list number by 1 when clicking a button

Hi,

 

I have read other threads on this and it seems simple butyy I just cant get it to work 😞

My requirement is simple. I have connected a sharepoint list to the Powerapp which is called SPLIST, which contains two fields, name and QTY)

On the edit screen, I have added a button and tried to set the onselect value to Patch (SPLIST,SPLIST.QTY,{QTY:SPLIST.QTY+1}) but it doesnt like the syntax. I have tried all different ways to specify the source and records to be updated but I just cant seem to get it.

Sorry, I'm an absolute newb to Powerapps so Im sure its something really simple I'm doing wrong?

 

Thanks very much in advance for any help!

10 REPLIES 10
mdevaney
Community Champion
Community Champion

@MikeWJS 

Like this... Change the ID number to match the record you want to PATCH.

Set(myRecord, LookUp(SPLIST, ID=1));
Patch(SPLIST, myRecord,{QTY:myRecord.QTY+1}) 


---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Paulo_VS
Advocate I
Advocate I

Hi guy,

 

I go try help you, lets go....

 

If you trying create a new line on click  =  Patch(SPLISTS, Defaults(SPLISTS), {Title: "Clicked", Other Variable: 1}

And if you try add on specif Line = Patch(SPLITS,  {ID : LineID}, { AddClicks : AddClicks + 1})

i hope this helps

Thanks for the responses both!

 

Sorry, I wasnt clearer.

How the app will work is to click the new record button, then the edit form will load.

The user enters the name of the record (e.g. Customers Name) and underneath it will be four different values, all defaulting to zero, with a button next to them so they can add one to the value each time they press the button (think picking a customers order, the button is pressed every time a product is added), hence I will not know the ID of the record to update, it is basically the current record.

Hope this makes sense?

Thanks again for taking the time to try and help me!

Ok, lets do this...

 

1 - On Screen going on "OnVisible" and put  = Set(num;1)

 

 

image.png

 

You finish set one variable when the Screen opens, 

 

Now you need config the label and buttons

Label Text = Variable

On Label : Text = VariableOn Label : Text = Variable

 

Buttons go update the values...

On Button = put this functionOn Button = put this function

 

 

When using a record that already exists in the variable you put = Set(num : ThisItem.NumProducts)

mdevaney
Community Champion
Community Champion

@MikeWJS 

My advice was not meant to hardcode a Product ID (example: 1).  It was meant for you to replace '1' with a dynamic reference to the ID you want to PATCH.

 

Set(myRecord, LookUp(SPLIST, ID=your_product_id));
Patch(SPLIST, myRecord,{QTY:myRecord.QTY+1}) 

 

If you need more direction, this all I can give until you show how the 'add product' UI is being accomplished and provide any relevant code.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up." 

Sorry both for being a total newb and being dumb!

 

@Paulo_VS Thanks, that kind of worked but the num value is not reset when the form is opened so when you create a new record it retains the last number instead of resetting to zero 😞

 

@mdevaney Im not sure how to to this, the ID would just be the current ID. I'll try to explain exactly what Im doing.

 

Ive created the list with customer (name), apples (value) and oranges (value) - fig 1

Created the app - fig 2

Run the app - fig 3

Create a new record - fig 4

Enter the customer name in the box (1), then add two buttons to increment the existing zeros for the quantity of each - fig 5

 

I basically do not know how to use the buttons to increment the figures next to them.

 

Thanks and sorry again!

 

 

 

 

hi @MikeWJS 

 

In the Apples field, put "ThisItem.Apples (NameOfCollumn) + num"
And the button, put UpdateContext ({num, +1})

Remembering to set the variable (num) when opening the screen  : Set(num , 0)

For reset values, use Reset(NameField);; Reset(Label);; Reset(TextInput)....

Once again, my sincerest apologies.

 

When you say the apples field, you mean in the default property when clicking on the field yes?

By name of the column you mean in sharepoint yes? If so the column is called apples so I have tried ThisItem.Apples (Apples) + num which gives the error invocation of unknown or unsupported function, see screenshot 1 of what I have done.

 

 

I have managed to use this method,

 

1) Add the Set(varIncrement,1) to the OnStart method of the App

2) Add Set(varIncrement, varIncrement + 1) to the BtnProceed OnSelect event

3) Set the Default property of the Textbox to varIncrement

 

With some success, however the Apples field always stays at the last number used instead of resetting to 0 each time the edit screen is opened, even though I have used set(num,0) in the onvisible box of the edit screen form.

 

Any ideas? This is so close now 😞 

 

Thanks again!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,315)