Previous Topic

Next Topic

Book Contents

Book Index

Script to Add Narrative Lines to an Invoice

This example shows you another way to record, save and play a basic script. This example also introduces you to error trapping. The script in this example will add two narrative lines to an invoice.

  1. Run the NewInvoice.pfs script created previously, you can use your shortcut to do so. The IN Enter Invoices form will open. Go to the Lines tab.
  2. Click Record (ALT+F1).
  3. Add the following narrative lines to the invoice:

    Note: The pop-up Narrative Editor (activated by clicking CodeEdit Open Narrative Editor in the Description field) is not supported by scripting, so cannot be used here.

  4. Move the cursor from the Description field to another field.

    Note: Any spelling mistakes you fix as you go are not recorded. Field entries are recorded after you move off the field, so don't end recording till you move past the last narrative description.

  5. Click Record (Alt+F1) to turn off the script recorder.

    Result: Script Editor opens and displays what it has recorded:

    Dim frmINInvoice1 as Object
    frmINInvoice1 = GetActiveObject
    If IsNull(frmINInvoice1) or frmINInvoice1.ClassName <> "INInvoiceEntryForm" then Error "Wrong form class for script"
    frmINInvoice1.Line.Append
    frmINInvoice1.Line.LineType = "Narrative"
    frmINInvoice1.Line.Description = "These goods remain the property of ABC"
    frmINInvoice1.Line.Append
    frmINInvoice1.Line.LineType = "Narrative"
    frmINInvoice1.Line.Description = "Holdings Limited until payment is received in full"

  6. Look at what the recorder has done to trap errors. The following part of the code means that an error message will be produced if the IN Invoice Entry form is not open when the script is run:

    If IsNull(frmINInvoice1) or frmINInvoice1.ClassName <> "INInvoiceEntryForm" then Error "Wrong form class for script"

  7. Save the script with the name InvoicePropertyStatement.pfs.
  8. Run the script. 
    Result: The script should add another two narrative lines to your invoice.
  9. Now select a Customer, then save the invoice. Try running the script again.
    Result: You should receive an Error message because you are not in Edit mode.
  10. To modify the script in Edit mode:

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

    frmINInvoice1.Edit
    frmINInvoice1.Line.Append
    frmINInvoice1.Line.LineType = "Narrative"
    frmINInvoice1.Line.Description = "These goods remain the property of ABC"
    frmINInvoice1.Line.Append
    frmINInvoice1.Line.LineType = "Narrative"
    frmINInvoice1.Line.Description = "Holdings Limited until payment is received in full"

  11. Run the script. Running from Script Editor ignores the Script Editor as the active object.
    Result: Accredo should move you into Edit mode (if it can) and append the lines. It doesn't matter if you are already in Edit mode.
  12. Now try running the script with a non editable invoice (one which is posted).
    Result: You should receive an Error message again because the invoice cannot be edited. At this point, you could add another step to the code to select if the invoice is editable and provide a simple error message (rather than the cryptic one displayed) if it isn't. However, this is not essential as the current Error message ensures no damage can be done.
  13. Save the Script.