Hi all- 3.7 here: I have a table called Inventory Scan. The table’s Primary Key is “Entry No.” which goes up by one with each record. There is another field called “Lot No.” which is acquired by scanning a pallet. My question is how do I stop from getting duplicate lot numbers in my table without making “Lot No.” the Primary Key? Here is some of the C/AL Code I have for the Lot No. - OnValidate() section. ILE=Item Ledger Entry Table, WHSE=Warehouse Entry Table… ********************************* ILE.SETRANGE (“Lot No.”,“Lot No.”); IF ILE.FIND(’-’) THEN; “Lot No.” := ILE.“Lot No.”; “No.” := ILE.“Item No.”; Qty := ILE.“Remaining Quantity”; WHSE.SETRANGE (“Lot No.”,“Lot No.”); IF WHSE.FIND(’-’) THEN; Bin := WHSE.“Bin Code”; User := USERID; IF “Lot No.” = ‘’ THEN ERROR(‘ERROR - Lot No. does not exist! Please enter a valid Lot No.’); IF Qty = 0 THEN ERROR(‘ERROR - QTY is zero in system. Please record Pallet ID and QTY manually.’); ********************************* How should I go about this situation? I have tried record.FIND to no avail. Any help? Thanks, JP
Hi JP, if i understand correctly the lot no. will be either typed in or read with a bar code scanner (in other words, it gets created externally), so you could simply use the following code to make sure that no duplicate lot no. exists: //create a new key in the table for this field InventScan2.SETCURRENTKEY("Lot No.") InventScan2.SETRANGE("Lot No.", InventScan."Lot No.") IF InventScan.FIND('-') then ERROR('Lot No. must be unique.');
And that should do. Saludos Nils
OK… When I try the following code it lets me enter one Lot No. into the table and then gives the error for any other records that I try to add. It seems as if it is just searching for any Lot No. and if one exists then it errors out. I put this in the Lot No. OnValidate() section in my Inventory Scan Table ********************************** InvScan2.SETCURRENTKEY(“Lot No.”); InvScan2.SETRANGE(“Lot No.”, InvScan.“Lot No.”); IF InvScan.FIND(’-’) THEN ERROR(‘Lot No. must be unique.’); ********************************** Anyone have any idea if I am missing something here? Seems like it should be an easy fix…but has been wooping me for a bit now. Thanks, JP
OK… I got it to work finally…it took the following: ************************************ InvScan.SETCURRENTKEY(“Lot No.”); InvScan.SETRANGE(“Lot No.”,“Lot No.”); IF InvScan.FIND(’-’) THEN ERROR(‘Lot No. must be unique.’); ************************************ Thanks for the help Nils…you are a life saver…! JP
… and I just realized the “little bug” in my code, that probably caused you the problem, in fact, this one could enter the list of “Navision programming classic”… //create a new key in the table for this field InventScan2.SETCURRENTKEY(“Lot No.”) InventScan2.SETRANGE(“Lot No.”, InventScan.“Lot No.”) IF InventScan2.FIND(’-’) then ERROR(‘Lot No. must be unique.’); Anyway, I am glad you figured it out and that it works fine [;)] Saludos Nils