This example shows you how to record a script to change an Invoice line Type from Product to Narrative or vice versa.
Alt+F1).(Alt+F1) to turn off the script recorder.Result: Script Editor opens and displays what it has recorded:
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"
frmINInvoice1.Line.LineType = "Narrative"
frmINInvoice1.Line.Description = "stuff"
Forms have an ActiveProperty property, that contains the form field that currently has focus. You can set the ActiveProperty to change the focus on the form. This lets us put the cursor in a field, without having to add text to the field.
To do this, change the last line of the script to:
frmINInvoice1.ActiveProperty = "Line.Description".
A new Script Editor window should show the code:
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"
frmINInvoice1.Line.LineType = "Product"
frmINInvoice1.ActiveProperty = "Line.Description"
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"
If frmINInvoice1.Line.LineType = "Product" then
frmINInvoice1.Line.LineType = "Narrative"
frmINInvoice1.ActiveProperty = "Line.Description"
ElseIf frmINInvoice1.Line.LineType = "Narrative" then
frmINInvoice1.Line.LineType = "Product"
frmINInvoice1.ActiveProperty = "Line.Description"
End If
'Toggle document line type between Narrative and Product
'Script Shortcut - Keyboard shortcut only Ctrl+\
Dim frmINInvoice1 as Object
frmINInvoice1 = GetActiveObject
If IsNull(frmINInvoice1) then
'Do nothing if no form open
ElseIf frmINInvoice1.ClassName = "INInvoiceEntryForm" or frmINInvoice1.ClassName = "POPurchaseOrderEntryForm" or frmINInvoice1.ClassName = "OESalesOrderEntryForm" then
If frmINInvoice1.Editing then
If frmINInvoice1.Line.LineType <> "Narrative" then
frmINInvoice1.Line.LineType = "Narrative"
frmINInvoice1.ActiveProperty = "Line.Description"
ElseIf frmINInvoice1.Line.LineType = "Narrative" then
frmINInvoice1.Line.LineType = "Product"
frmINInvoice1.ActiveProperty = "Line.ProductCode"
End If
Else
Abort(frmINInvoice1.ClassName & " not in Edit mode, cannot change line type.")
End If
ElseIf frmINInvoice1.ClassName = "JCBatchTransactionEntryForm" or frmINInvoice1.ClassName = "JCTimesheetTransactionEntryForm" then
If frmINInvoice1.Editing then
If frmINInvoice1.Line.TransactionType <> "Narrative" then
frmINInvoice1.Line.TransactionType = "Narrative"
frmINInvoice1.ActiveProperty = "Line.Description"
ElseIf frmINInvoice1.Line.TransactionType = "Narrative" then
frmINInvoice1.Line.TransactionType = frmINInvoice1.TransactionType
If frmINInvoice1.CostCentreCode <> "" Then frmINInvoice1.Line.CostCentreCode = frmINInvoice1.CostCentreCode
If frmINInvoice1.ComponentCode <> "" Then frmINInvoice1.Line.ComponentCode = frmINInvoice1.ComponentCode
If frmINInvoice1.ProductCode <> "" Then frmINInvoice1.Line.ProductCode = frmINInvoice1.ProductCode
If frmINInvoice1.CreditorCode <> "" Then frmINInvoice1.Line.CreditorCode = frmINInvoice1.CreditorCode
If frmINInvoice1.Unit <> "" Then frmINInvoice1.Line.Unit = frmINInvoice1.Unit
frmINInvoice1.ActiveProperty = "Line.TransactionQuantity"
End If
Else
Abort(frmINInvoice1.ClassName & " not in Edit mode, cannot change line type.")
End If
ElseIf frmINInvoice1.ClassName = "JCJobForm" then
If frmINInvoice1.Editing then
If frmINInvoice1.Estimate.EstimateLineType <> "Narrative" then
frmINInvoice1.Estimate.EstimateLineType = "Narrative"
frmINInvoice1.ActiveProperty = "Estimate.Description"
ElseIf frmINInvoice1.Estimate.EstimateLineType = "Narrative" then
frmINInvoice1.Estimate.EstimateLineType = "Material"
frmINInvoice1.ActiveProperty = "Estimate.ProductCode"
End If
Else
Abort(frmINInvoice1.ClassName & " not in Edit mode, cannot change line type.")
End If
ElseIf frmINInvoice1.ClassName = "APShipmentEntryForm" then
If frmINInvoice1.Editing AND frmINInvoice1.ActivePage = 2 then ' if in edit mode and in the lines tab
If frmINInvoice1.Line.LineType <> "Narrative" then
frmINInvoice1.Line.LineType = "Narrative"
frmINInvoice1.ActiveProperty = "Line.Description"
ElseIf frmINInvoice1.Line.LineType = "Narrative" then
frmINInvoice1.Line.LineType = "Product"
frmINInvoice1.ActiveProperty = "Line.ProductCode"
End If
Else
Abort(frmINInvoice1.ClassName & " not in Edit mode or not in the Lines tab, cannot change line type.")
End If
Else
'Do nothing if wrong form open
End If
frmINInvoice1 = Nothing
The first two lines document what the script is for. The apostrophe at the start of the line "remarks" out the line so it is not treated as part of our code. The script has been structured to fail silently if run in the wrong place, but to tell the user what is wrong if run in the right place but wrong context, such as if you are not editing your document.