Previous Topic

Next Topic

SF Tutorial: Select Multiple Products on Invoice

This tutorial will show you how to create a scripted form to let you search for Products, then select multiple products and add them to an Invoice.

  1. Open the Script Editor to create a script, by clicking Record Script (Alt+F1) then Stop Recording (Alt+F1) on the main toolbar. Alternatively, go to Accredo > Script > Script Editor.
  2. First, enter the following code to ensure the code will be called from the IN Invoice Entry Form.

    Dim frmINInvoice1 as Object
    frmINInvoice1 = GetTriggerObject
    If IsNull(frmINInvoice1) Then frmINInvoice1 = GetActiveObject
    If IsNull(frmINInvoice1) or frmINInvoice1.ClassName <> "INInvoiceEntryForm" Then Error "Wrong form class for script"

  3. Enter the following code to declare variables required:

    Dim ctrlWords as Object
    Dim ctrlAny as Object
    Dim ctrlPartial as Object
    Dim tblLookup as Object
    Public strProdWords as String
    Public boolAnyWords as boolean
    Public boolPartWords as boolean
    If IsNull(boolAnyWords) Then boolAnyWords = ApplicationSetting("IC\WordAnyWords")
    If IsNull(boolPartWords) Then boolAnyWords = ApplicationSetting("IC\WordPartialMatch")

  4. Create a Memory Table using the Wordlookup function. This will create a memory table to store the products selected, and the quantity of each product. Use the following code:

    ' create template memtable
    dim tblTemp as Object
    tblTemp = WordLookup("ICPROD","",False,False)
    dim Builder as Object
    Builder = CreateObject("Accredo.MemoryTableBuilder")
    Builder.Clone(tblTemp)
    Builder.AddField("Selected","Quantity")
    tblLookup = Builder.CreateTable
    tblLookup.Fields.Item("Selected").Index = 0
    tblLookup.Fields.Item("Selected").DisplayWidth = 10

  5. Create the scripted from to display and capture the products:

    ' Selection Dialog using Scripted Form Object
    Dim scForm1 as Object
    scForm1 = CreateObject("Accredo.ScriptedForm")
    scForm1.Caption = "Product Lookup"

  6. Set up the scripted form with options for Any Word and Partial Word, similarly to the standard Accredo Word Lookup:

    ctrlWords = scForm1.InputBox("Words","Words")
    scForm1.SetValue("Words",strProdWords)
    ctrlAny = scForm1.InputBoolean("Any","Any Word")
    scForm1.SetValue("Any",boolAnyWords)
    ctrlPartial = scForm1.InputBoolean("Partial","Partial Word")
    scForm1.SetValue("Partial",boolPartWords)

  7. Add a Lookup button to the form, similarly to the standard Accredo Word Lookup:

    Dim btnLookup as Object
    btnLookup = scForm1.InputButton(2106,addressof(onButtonClick), "&Lookup")

  8. Add the code to perform the lookup when the button is clicked. First, add a OnButton Click Sub routine. Add this code at the start of the script, before the main code.

    Sub OnButtonClick(Sender as Object)
      OnLookup(ctrlWords.Value,ctrlAny.value,ctrlPartial.Value)
    End Sub

  9. Add a OnLookup Sub routine to perform the lookup. Again, add this code at the start of the script, before the main code.

    Sub OnLookup(LookupWords as String, AnyWords as boolean, PartialWords as Boolean)
      Dim tblLookupResult as Object
      tblLookupResult = WordLookup("ICPROD",LookupWords,AnyWords,PartialWords)
      tblLookup.Empty
      tblLookupResult.First
      Do Until tblLookupResult.EOF
        tblLookup.Append
        CopyFieldsByName(tblLookupResult,tblLookup)
        tblLookup.Save
        tblLookupResult.Next
      Loop
      tblLookup.First
      tblLookupResult = nothing
    End Sub

  10. Add a grid to display the products found:

    Dim ProdGrid as Object
    ProdGrid = scForm1.InputGrid("ProductList", "",tblLookup, 500,885)
    ProdGrid.InputNumber("Selected")

  11. You now have the code to display the scripted form. Next, add the code to run the form. Start with a loop to contain the form. Code in the following steps will go into this loop, between the Do and Loop, and will be indented.

    Do
      '<following code goes here>
    Loop

  12. Write the code to execute the form. This goes after the Do, and before the Loop statements above. Code in the following steps will go into the If - Then section.

      If scForm1.Execute Then
        '<following code goes here>
      Else
        Abort("",True)
      End If

  13. Add code to loop through the memory table created previously (tblLookup) and add all selected products to the Invoice. Add this code between the If and Else statements added in the previous step.

        scForm1.BringtoFront
        tblLookup.First
        Do Until tblLookup.EOF
          If tblLookup.Selected <> 0 Then
            frmINInvoice1.Line.Next
            If not frmINInvoice1.Line.EOF Then
              'step to the end of any kitset
              Do Until frmINInvoice1.Line.LineType = "Product" or frmINInvoice1.Line.LineType = "Narrative" or frmINInvoice1.Line.EOF
                frmINInvoice1.Line.Next
              Loop
              If not frmINInvoice1.Line.EOF Then
                frmINInvoice1.Line.Insert
              Else
                frmINInvoice1.Line.Append
              End If
            Else
              frmINInvoice1.Line.Append
            End If
            frmINInvoice1.Line.ProductCode = tblLookup.ProductCode
            frmINInvoice1.Line.QuantitySupplied = tblLookup.Selected
          End If
          tblLookup.Next
        Loop
        strProdWords = scForm1.GetValue("Words")
        boolAnyWords = scForm1.GetValue("Any")
        boolPartWords = scForm1.GetValue("Partial")
        Exit Do

  14. Save the script.
  15. Go to Accredo Toolbar > ScriptAddShortcut Add Shortcut.
  16. Add a shortcut button to the InInvoiceEntryForm toolbar, linked the the saved script. Select a Glyph for the button.

You can now go to the IN Invoice Form, and click the button added to search for products, then enter products found in multiple quantities.

The entire script for this tutorial is at SF Script: Select Multiple Products on Invoice. You can cut and paste this script into the script editor to create this function.

In This Section

SF Script: Select Multiple Products on Invoice

See Also

Module Tutorials

Book Contents

Book Index