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.
Alt+F1) then Alt+F1) on the main toolbar. Alternatively, go to Accredo > Script > Script Editor.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"
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")
' 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
' Selection Dialog using Scripted Form Object
Dim scForm1 as Object
scForm1 = CreateObject("Accredo.ScriptedForm")
scForm1.Caption = "Product 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)
Dim btnLookup as Object
btnLookup = scForm1.InputButton(2106,addressof(onButtonClick), "&Lookup")
Sub OnButtonClick(Sender as Object)
OnLookup(ctrlWords.Value,ctrlAny.value,ctrlPartial.Value)
End Sub
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
Dim ProdGrid as Object
ProdGrid = scForm1.InputGrid("ProductList", "",tblLookup, 500,885)
ProdGrid.InputNumber("Selected")
Do
'<following code goes here>
Loop
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
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
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.