Button that increments a field and saves the record

Hello,

This might seem simple to some, but I need help making a button that increments field1 when clicked and saves the record after it increments only if the number in field1 is less than the number in field2.

example

{field1} = 1
{field2} = 3

button onclick = +1 to field1 and save

If
{field1} = 3
{field2} = 3

button onclick error message

the value in field1 can never be incremented to a value that is higher than the value in field2

There are many ways to do this I’m sure but, I have no idea where to start.

Put the check in the onvalidateevent. It will be triggered when hitting save/insert. If there’s an error then you can use the snippet on the right side of the editwindow (show error and exit), otherwise add 1 to your field. If you only want to add 1 on insert then you need to apply the increase of the field in the onbeforeinsert event. That’s all. You don’t need to create a button for this.

Audcom,

I appreciate your information but, I want a button called “Checkout” that when pushed changes the number of items available. The user will essentially be checking out an item for use and the inventory needs to reflect the proper amounts available after checkout. In that case I don’t need it to add 1 every time I save.

Thank you for all your help, here and other posts. You seem to be a crucial member of this forum.:slight_smile:

Thanks!

It function is very neccesary for a form, i had the same problem, i hope that SC team add it functionality.

Could you give some more info on this. I still don’t see what you want couldn’t be achieved. You want to add a button to do this. You can. You need to use a sc_redir to the same page if you don’t want to have an ‘ok’ message and stay on the same page. You have to use a commit to be sure that updates are done because if you use a sc_redir this commit is not automatically. But, checkout means that you go into some overview of a shoppingcart right? Jump to another form? If checkout is broken off does the amount needs to be restored?

It would be nice though to be able to create a button to refresh the same form without the hassle. You can put an image on the form and use the onclick ajax event. If the image looks like a button with the text checkout… Just thinking…

This is an inventory app. The form displays information about the product including quantities on hand and available. When said checkout button is clicked, the inusequantity field should increase by one. While I’m at it I guess I should create a return button that does the opposite. This kind of functionality is not really necessary but the more little things I can figure out for the future the better. I did as you suggested and created an field with an ajax event with sc_commit and sc_redir but ajax event is not available for a created field of type html image:(.

After thinking about this further, I’m just going to forget about it since it seems more complicated than it’s worth. Thanks for your help anyway!