Check sum(Qty) in DataSource and Compare with Form

Hi all,

I hv formA with dataSource tableA

tableA hs fields : itemID, Qty, Status

In formA I can add qty minus or plus.

But whenever I add the minus Qty, i need to check to sum(Qty) in tableA whether the Qty is below 0 or not .

I wrote this, but doesnt work

method: validateWrite

tableA a;

while select sum(Qty) from a group by a.ItemId where a.status::bad
{
if (Qty<0)
{
error(“Message”);
ret=false;
}
}

Hi,

you can validate the Qty in validateWrite method but the error will be shown to the user while saving the record.

If you don’t want the user to enter 0 (or sum shouldn’t 0) then place the same code in validateField method for Qty field.

Thanks.

Note that if you run the validation before saving, the current record won’t be included in the sum. Your calculation should check whether {sum of already saved} + {Qty being saved} < 0.

Thx for the reply

But i didnt see any validateField method in QtyField.

what method should i write it on?

i hv tried to write in method validate in QtyField, but it didnt work

And why it doesn’t work? Is the calculated value what you expect? You will find the answer in the debugger, not here.

the calculation is fine. but i’m just curious what method should i use for this case.

to be honest i am not very familiar with the method provided by ax

now the case is solved. i used canClose for the validation