Script Example: Unique Stock Alternate Codes


 

The following sample script can be placed inside STOCK.MAC and is designed to work with the Stock Control component.

The purpose of the script is to prevent duplicate alternate product codes from being entered in stock control. This would be useful if the alternate product code was being used as a bar code reference and you wanted to ensure that the same code cannot be entered on more than one product record at a time.

Sample Script: STOCK.MAC

If Mode == 9

   If Focus == "NAME2"

      Declare nRecNo Type Number

      nRecNo := Stock->(RECNO())

      If stock->(Find(Upper(SCRREAD("Name2")), "NAME2"))

        If Stock->(RECNO()) # nRecNo

           Stock->(Goto(nRecNo))

           Echo("Sorry, this code already exists.")

           SCRWrite("NAME2", "")

           SCRFocusOn("NAME2")

           Return

        Endif

     Endif

     Stock->(Goto(nRecNo))

   Endif

generate/mistake1.gifIt is very important that if a script changes the record position of a stock item, it restores that record position before exiting. This is what the Stock->(Goto(nRecNo)) statement does.

____________________________

Related Topics:

Script Programming

Script Samples



Help Topic Map