I’m facing a challenge in my project and could really use some help.
I have two tables: Work Orders and Stock (Inventory). I want to ensure that stock quantities never go negative. For example, if a product has 9 units in stock, users should not be able to add more than 9 of that product to a work order.
I tried linking the Quantity (Number) Component to the Stock table, but it only allows selection from the Work Orders table/column.
One potential solution I considered was using an IF-Then-Else column to detect when a product’s quantity reaches zero and prevent further additions. However, this approach doesn’t work if the remaining stock is, say, 4, and user tries to add 5 units at once—since the check only triggers when the stock hits zero, it wouldn’t prevent that action in advance.
Any suggestions on how to handle this? Thanks for your time!
You are trying to lookup the “max value” in a form, that won’t happen naturally due to the sandbox nature of the form.
You have 2 ways to go here:
First method: For the Product ID choice, create a column in your users table for it, and write to that column instead of the Product ID in your Work Orders table. Then, add a special value in your form to write User Profiles > Product ID to the Work Orders.
This allows you to access the Product ID value whilst still inside the form. From that value, you can create a relation & lookup to retrieve the max value allowed for the quantity.
1. Using a “Show New Screen” Instead of a Form Page
Instead of using a form page, I switched to a “Show New Screen” approach. This was crucial because, in a new screen, data updates instantly as users enter values.
2. Storing Temporary Data in the User Table
To track selections in real time, I created temporary columns in the User table. As soon as a user selected a product, its Product ID was stored in the User table.
3. Fetching Available Stock Dynamically
I created a relation from the User table to the Stock table based on the selected Product ID and then used a lookup column to fetch the available stock quantity. This allowed me to dynamically set the maximum allowable value in the quantity input field.
4. Preventing Over-Selection with a Workflow Condition
While setting a max value helped, users could still bypass it by manually entering a larger number and clicking submit. To solve this, I added a workflow condition:
If the entered quantity exceeds the available stock, the submission is blocked, and an error notification appears.
If the quantity is valid, the process continues as normal.
Conclusion
By using the Show New Screen instead of a form, storing temporary selections in the User table, fetching stock availability via relations and lookups, and enforcing a workflow condition, I successfully prevented stock from going negative in work orders.
I hope this helps anyone facing a similar issue! Let me know if you have any questions