5 Replies Latest reply on Dec 7, 2010 9:14 AM by philmodjunk

    how to use script

    benkryton

      Title

      how to use script

      Post

      Hi,

      I'm new to FM so please go easy on me. I am trying to make a very basic stock control system and I'm not sure how to make a script. I have a simple stock locator database that consists of part numbers, quantity and bin location. I have two buttons. "Part in" and "part out".  I would like to make a text box that I can type a part number into and then press either  the "part in" or "part out" button to perform the following:

      Part IN - Check to see if the part already exists in the data base. If yes, then increase quantity by one and display the record to indicate the bin location. If the part number does not exist in the database then create a new record with quantity set to 1 and display the record to allow the bin location to be added.


      Part out - find and display the record and minus one from the quanty field and acknowledge it has been sucessfull in doing it.

      I have two layouts. One displays the part #, quantity and bin and the other is more of a home layout that has the two buttons and a text box ready for the part # to be added.

      Can anyone point me I the right direction?

        • 1. Re: how to use script
          philmodjunk

          Do you know how to use Manage Scripts to create a new script?

          If you do, then here's the Part In script:

          Make your "text box" a field with global storage. Find its field definition in Manage | Database | fields, double click it and select this option on the storage tab of the Field Options dialog that pops up. I'll refer to this field as gPartNumber in the script below.

          Go To Layout [ Parts ]
          Enter Find mode [] // clear the pause check box
          Set Field [Parts::PartNumber ; parts::gPartNumber]
          Set Error capture [on]
          Perform Find[]
          If [ Get ( FoundCount ) = 0 /* No part of that number */]
              New Record/Request
              Set Field [ Parts::Part Number ; parts::gPartNumber ]
          Else
               Set Field [ Parts::Qty ; Parts::Qty + 1]
          End If

          You can format gPartNumber with a value list of PartNumbers to reduce data entry errors.

          Once you have this script working for you, you may want to add a few steps that pops up a dialog asking for confirmation from the user before creating a new record. That way, you can avoid creating a new record after incorrectly entering a part number.

          • 2. Re: how to use script
            benkryton

            Thanks for that Phil, The script works great!

            The only drama I have is if I have lets say a part #'s like  6871 and 6872 and entered part # 68, instead of making a new record it finds it as 6871 instead and adds 1 to the qty.

            I thought the find function needs to be more specific as to match the complete part number not just the start of it but I can't figure out how to change that part of the script. 

            I tried as you suggested & set the value list to part number but it returns an error if the part # doesn't already exist and promts me to use it anyway instead of just creating a new record.  Can you or anyone help?

            • 3. Re: how to use script
              philmodjunk

              Silly me, I assumed parts number was a number instead of text.

              Change the script like this:

              Enter Find mode [] // clear the pause check box
              Set Field [Parts::PartNumber ; "==" & parts::gPartNumber]

              This sets up the find for an exact match.

              I tried as you suggested & set the value list to part number but it returns an error if the part # doesn't already exist and promts me to use it anyway instead of just creating a new record. 
              I'm afraid that doesn't make any sense to me for the script I've described. How exactly did you set up your value list? When do you see an error message and what exactly does that error message say?

              • 4. Re: how to use script
                benkryton

                Thanks again Phil. The search works heaps better now. I should have meantioned the part number contains both numbers and text.

                As for the error. I went into manage database and then set up gpartnumber as a member of the value list - and then made a new value list that is part number. 

                If I were to enter a part number that is not already in the database it pops up a window that says "gnumber" is definded to contain only specific values - Allow this value? then there is three buttons that can be selected named "revert" "yes" or "no"

                If I press revert it goes to the layout with no part number in the field.

                If I press yes it takes me to the layout then put that searched part number into the field.

                If I press no it pops up another window that says "go to layout has been cancelled, continue with script? and two buttons yes or no.

                If I take the value list off the script works fine without the interuption. It would be good however, as you suggested, if it would ask a simple prompt if a part number didn't exist " part number does not currently exist, create new part number?" and then two buttons that say yes or no. If yes then it just continues with the script but if no is selected it just clears the field and stays on the current "home layout". 

                I'm a bit confused as to what the value list does and how it is useable?

                • 5. Re: how to use script
                  philmodjunk

                  Knowing that you wanted to be able to add new part numbers, I suggested a drop down list of the part numbers currently entered in records in your table. What you have defined, is a validation rule that insists that the entered value be a member of your value list and I don't think that really works here.

                  With a drop down list, the user can select from the existing part list or type in a new one. This is a format you specify in the inspector--not field options.