The following is the entire script for the SF Tutorial: Select Multiple Products on Invoice. Refer to the tutorial for information on how to use this script.
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")
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
Sub OnButtonClick(Sender as Object)
OnLookup(ctrlWords.Value,ctrlAny.value,ctrlPartial.Value)
End Sub
' 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
'DocumentObject(tblLookup)
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")
Dim ProdGrid as Object
ProdGrid = scForm1.InputGrid("ProductList", "",tblLookup, 500,885)
ProdGrid.InputNumber("Selected")
Do
If scForm1.Execute Then
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
Else
Abort("",True)
End If
Loop