Incorrect stock amount when editing


I’ve used Valid_if to make the amount that can be used as an ingredient maximum to the amount that is left in Stock. This works correctly. I’ll try to explain the problem with an example (I used kg instead of Bulk Units):

500 kg in Stock; used 400 kg as an ingredient; makes 100 kg left in stock.


When edititing the amount of ingredients in this case it seems that the maximum value is now set to 100 kg, so the original amount of 400 kg cannot even be entered when editing. The maximum amount should be set to 500 kg. I tried to use [Stock] + [_THIS] or [Stock] + [Amount BU], but without any succes, because when entering 450 kg, the maximum amount would be 550 kg.

I cannot seem to find the amount that has already been saved instead of the amount that has been entered in the field. Does anyone have experience with this problem?

Thanks for your time.

Yes. You will want to take advantage of the static values [_THISROW_BEFORE] and [_THISROW_AFTER].

The Valid_If expression would need to be something like this:

[Stock] - [_THISROW_AFTER].[Amount BU] + [_THISROW_BEFORE].[Amount BU] >= 0

On new entry, [_THISROW_BEFORE].[Amount BU] = 0 so:

500 - 400 + 0 = 100 which is >= 0

When editing and changing value from 400 to 450:

100 - 450 + 400 = 50 which is still >= 0

@WillowMobileSystems Yes! Amazing! This is exactly what I needed. Thank you very much John!