Sage 100 User-Defined Script Generator
This generator writes a Sage 100 user-defined script (VBScript) for the sales order or invoice header that reads the customer's credit hold flag, copies it into a UDF and can stop the save. It targets Sage 100 Standard, Advanced and Premium, 2019 to 2025, where Custom Office scripting runs inside the business objects.
Fill in
Both tables carry ARDivisionNo$ and CustomerNo$.
Only Pre-Write can stop the save with SetError.
User-defined script (VBScript)
' Sage 100 UDS - SO_SalesOrderHeader - Table - Pre-Write
' Copies AR customer CreditHold$ into UDF_CREDIT_HOLD$ and optionally blocks the save.
retVal = 0
sDiv = ""
sCust = ""
sHold = ""
retVal = oBusObj.GetValue("ARDivisionNo$", sDiv)
retVal = oBusObj.GetValue("CustomerNo$", sCust)
If sCust <> "" Then
Set oCust = oSession.AsObject(oSession.GetObject("AR_Customer_svc"))
retVal = oCust.SetKeyValue("ARDivisionNo$", sDiv)
retVal = oCust.SetKeyValue("CustomerNo$", sCust)
retVal = oCust.Find()
If retVal = 1 Then
retVal = oCust.GetValue("CreditHold$", sHold)
retVal = oBusObj.SetValue("UDF_CREDIT_HOLD$", sHold)
If sHold = "Y" Then
If "Yes" = "Yes" Then
retVal = oScript.SetError("Customer is on credit hold. Contact credit control before saving.")
ElseIf oSession.UI <> 0 Then
retVal = oSession.AsObject(oSession.UI).MessageBox("", "Customer is on credit hold. Contact credit control before saving.")
End If
End If
End If
' retVal = oScript.DebugPrint("Cust " & sDiv & "-" & sCust & " hold=" & sHold)
Set oCust = Nothing
End IfWhere to attach it
| Setting | Value |
|---|---|
| Menu | Custom Office > Main > User-Defined Script Maintenance |
| Table | SO_SalesOrderHeader |
| Event | Table - Pre-Write |
| UDF needed | UDF_CREDIT_HOLD$ (string) created in User-Defined Field and Table Maintenance |
| After saving | Compile the scripts, then have users close and reopen the task |
Works in Sage 100 Standard, Advanced and Premium (Standard runs scripts on the workstation, Advanced and Premium on the server) and requires custom office scripts enabled for the company in Company Maintenance. String fields end in $ (CustomerNo$, CreditHold$); numeric fields such as CreditLimit do not, and their variables must start as 0, not "". SetError only stops the write on pre-events; on Column Post-Validate it does not undo the value, which is why the generator shows a message instead. Uncomment DebugPrint only while testing with the debugging window on. Scripts that call external COM objects need Allow External Access checked in Company Maintenance. Verify field names in the Sage 100 File Layouts for your version.
Want this script reviewed?
Send us your table, event and rule and we will check the script against your Sage 100 version.
Optional. The tool and every export work without this. No spam.
How to use it
Pick the table and event, keep CustomerNo$ as the source field unless your customer number sits in another field, and type the UDF that should receive the flag. Choose whether the script blocks the save. Copy the code, then in Custom Office open User-Defined Script Maintenance, add a script for the same table and event, paste the code and accept. Compile the scripts when prompted. Create the UDF first in User-Defined Field and Table Maintenance, as a string of length 1, or SetValue returns 0 and nothing is written.
- Table Pre-Write: the only option here that can cancel the save.
- Column Post-Validate: attach to CustomerNo to set the UDF the moment the customer is entered.
- Test in a copy of the company, not the live one.
Objects the script uses
oBusObj is the business object the script is attached to; GetValue and SetValue read and write its fields by name. oSession is the Sage 100 session: GetObject("AR_Customer_svc") returns a handle to the customer service object and AsObject turns the handle into an object you can call. On the service object, SetKeyValue sets each key column (ARDivisionNo$ and CustomerNo$) and Find() reads the record, returning 1 when found. oScript is the script context: SetError raises an error that cancels a pre-event, and DebugPrint writes to the debugging window. oSession.UI is 0 when no user interface is present, for example when the business object runs from Visual Integrator or BOI, so always test it before calling MessageBox.
Worked example
Customer 01-ABF has Credit Hold set to Y in Customer Maintenance. With Table Pre-Write and block save Yes, a user who tries to accept a sales order for 01-ABF gets the message and the order stays on screen unsaved; UDF_CREDIT_HOLD$ is set to Y on the header. With Column Post-Validate attached to CustomerNo and block save No, the UDF is filled and the user sees a message box as soon as the customer is entered, but can still save. A VI import for the same customer gets the SetError text in the import log on Pre-Write and no message box, because oSession.UI is 0.
Version differences and gotchas
In Advanced and Premium the script runs on the server, so it cannot touch files or COM objects on the user's workstation; in Standard it runs where the task runs. Changes made in a Column Pre-Validate script can be overwritten by Sage's own validation that follows, which is why Post-Validate is the usual choice for setting values. Sage 100 already has built-in credit checking in Sales Order Options; use this script when you need a different rule or a visible flag on the order. After every product update, recompile scripts and retest them.
Frequently Asked Questions
Where do I add a user-defined script in Sage 100?
Open Custom Office > Main > User-Defined Script Maintenance, choose the table (for example SO_SalesOrderHeader), add a new script with the event you want (Table Pre-Write, Column Post-Validate and so on), paste the code and accept. Compile the scripts when prompted and reopen the task to load them.
How do I stop a save from a Sage 100 script?
Call oScript.SetError("message") from a pre-event such as Table Pre-Write. Sage 100 cancels the write and shows the message to the user, or logs it for VI and BOI. On post-events SetError does not undo anything that already happened, so use a pre-event when you need to block.
Why does my script not change the field value?
Common reasons: the UDF does not exist or has a different name, the field is numeric but you passed a string (or the reverse), the script is attached to a Pre-Validate event and Sage's own validation overwrote the value, or the scripts were not compiled. Check the SetValue return: 1 means success, 0 means failure.
How do I show a message box from a Sage 100 script?
Use retVal = oSession.AsObject(oSession.UI).MessageBox("", "text"), but only when oSession.UI is not 0. When the business object runs from Visual Integrator, BOI or a web service there is no user interface and the call fails, so guard it with If oSession.UI <> 0 Then.
If you want staff to ask Sage 100 about customers, holds and open orders in plain English on your own servers, we can add that layer for you.
Related Tools
Sage 100 Business Object Interface (BOI) Sales Order Script Generator
Produces a working PowerShell script that logs in to Sage 100 through BOI, creates a sales order with one line and reports Sage's own error message on failure.
Other ERPsSage 100 ProvideX Error Codes Reference (Error 12, 43, 65, 88, 200)
Searchable list of the ProvideX run-time errors Sage 100 users actually see, with the exact message text, the usual Sage 100 cause and the first check to run.
Other ERPsSage 100 Version Upgrade and Data Migration Checklist (2023 to 2025)
A step list for moving Sage 100 Standard, Advanced or Premium to a new major version with a parallel install, covering customizations, reports, integrations and go-live.
Other ERPsSage 100 Table and Module Prefix Reference
Find the Sage 100 module prefix and the commonly used table names for items, customers, vendors, orders and bills of material.
More Other ERPs tools
See all- Sage 100 Year-End Close Checklist (Module Order SO, PO, IM, AR, AP, GL)
- Infor VISUAL Work Order Status and Structure Reference
- Infor VISUAL Manufacturing Scheduling Checklist
- Infor XA (MAPICS) Period End Close Checklist
- Infor VISUAL Database Table Reference
- Infor XA (MAPICS) Application Module Reference
- IBM i Commands for Infor XA Administrators Reference
- Acumatica Generic Inquiry Design Template
- Acumatica Manufacturing Edition Setup Checklist
Keep exploring
Free tools
- Sage 100 Business Object Interface (BOI) Sales Order Script GeneratorProduces a working PowerShell script that logs in to Sage 100 through BOI, creates a sales order with one line and reports Sage's own error message on failure.
- Sage 100 and Sage 300 Private AI Layer Blueprint GeneratorGenerate an architecture plan for a private AI assistant on on-prem Sage 100 or Sage 300: reporting copy or ODBC extract, Web API or BOI, retrieval, local GPU model and audit.
- Sage 100 Table and Module Prefix ReferenceFind the Sage 100 module prefix and the commonly used table names for items, customers, vendors, orders and bills of material.
ERP fixes and how-tos
- Sage 100 Business Object Interface (BOI): Working VBScript ExampleWorking Sage 100 BOI pattern: ProvideX.Script, SY_Session logon, nSetCompany, reading a customer and writing records, plus the errors and security settings that break it.
- How to Add AI to Sage 100 and Sage 300 On-PremPrivate AI architecture for on-prem Sage 100 and Sage 300: ODBC or SQL extracts, Sage 300 Web API, Sage 100 BOI, local GPU model, permissions and audit log.
- How to Add User Defined Fields (UDFs) in Sage 100How to add a user defined field in Sage 100 with Custom Office, place it on a panel, and expose it to reports, ODBC and imports, with the usual UDF pitfalls.
AI on your ERP
- AI for Sage 100 Small Manufacturers: Practical Answers From Work Orders, BOMs and InventoryPractical AI for small manufacturers on Sage 100: ask about work orders, BOMs, stock and shortages in plain English via ODBC or SQL, kept on a small server.
- AI for Sage 100, Grounded in Your MAS90/200 DataPut AI on Sage 100 and the Sage 100 Manufacturing (MRP) data set without sending data to a public model. Private LLMs and agents grounded in your MAS90/200 tables.
Integrations
- How to add Microsoft Teams to Sage 100Add Microsoft Teams to Sage 100: adaptive card approvals, credit hold and PO alerts, Entra ID sign-in, and a bridge that works with an on-prem Sage server.
- How to use ChatGPT with Sage 100How to use ChatGPT with Sage 100: exports versus live access, custom GPT actions, enterprise data controls, and when a private model is the safer choice.