Movement Journal with Unique Batch Numbers

Hi everyone,

Inside movement Journal, I want the application to check if the entered batch number is previously entered in another movement journal or not. If the batch number was entered before (in another movement journal or another line of present journal) user must be restricted from entering this batch.

What I did in this regard, was to override validate() method of “inventJournalMovement” form as follows:

public boolean validate(){

boolean ret;

ret = super();

ret = ret && element.checkDuplicateLine(InventDim.InventBatchId);

return ret;

}

Also I created a method for this form as follows:

public boolean checkDuplicateLine(InventBatchId _inventBatch)

{

select count(InventBatchId) from inventDim exists join inventJournalTrans

where inventDim.InventDimId == inventJournalTrans.InventDimId

&& inventDim.inventBatchId == _inventBatch;

if(str2int(inventDim.InventBatchId) > 0){

print “false”; //just for checking the value

return false;

}

else{

print “true”;

return true;

}

}

My problem here is that it looks like checkDuplicateLine method runs twice, because I receive two values, once it returns false, and then it returns true. I can’t understand why this happens or how to solve it. I’m using AX 2012.

Could anyone please help me how to fix this issue?

Thanks in advance

that means when it get saves, it return true, as you are also considering the current record in checkDuplicateLine. take new table buffer and dont consider the current record

Which method you have overriden?