2026-11-27

Sage 100 Script for Customer Pricing

A Sage 100 script for customer pricing that uses Find() never finds the record. Use GetResultSets on IM_PriceCode_svc with the KCUSTOMER index instead — here is the working VBScript.

The goal: during Sales Order entry, as soon as a line item is entered, warn the order taker if this customer has customer-specific pricing for that item. The natural first attempt — open IM_PriceCode with the business object, set the key values, browse the KCUSTOMER index and Find() — reports "not found" forever, even when the pricing record is sitting right there in the price code file and every value checks out in Data File Display and Maintenance.

Skip the Find() route. The lookup that works is a single GetResultSets call against the price code service object, using a padded begin/end key range on the KCUSTOMER index.

The fix

Attach the script to the sales order line's ItemCode Post-Validate event (table SO_SalesOrderDetail). In outline, the script:

  1. Reads the line's ItemCode$ from the line object, and ARDivisionNo$ and CustomerNo$ from the header object.
  2. Gets the price code service object — not the business object used in the failed attempts:

    Set oPrice = oScript.AsObject(oSession.GetObject("IM_PriceCode_svc"))
    
  3. Pads the customer number and item code to their full field lengths with null characters. This padding is the part everyone misses: the KCUSTOMER index key stores CustomerNo in a 20-character field and ItemCode in a 30-character field, and the range you pass has to match that layout.

    padString = String(30, CHR(0))
    cDiv  = "01"                                  ' division from the order header
    cCust = Left("ABF" & padString, 20)           ' customer number, padded to 20
    cItem = Left("1001-HON-H252" & padString, 30) ' item code, padded to 30
    results = ""
    

    (In a live script, cDiv, the customer and the item come from the header and line values read in step 1, not from literals.)

  4. Makes one GetResultSets call. The begin key is division + padded customer + padded item; the end key is the same string plus CHR(254), which closes the range on exactly that key; the index is KCUSTOMER:

    r = oPrice.GetResultSets("ItemCode$", "ItemCode$", results, "", "", _
            cDiv & cCust & cItem, cDiv & cCust & cItem & CHR(254), "KCUSTOMER")
    
  5. Tests the return value and nothing else: r = 1 means a customer pricing record exists for that division/customer/item — display (or speak) your "customer pricing" alert. r = 0 means there is none.

That is the whole technique. GetResultSets replaces the entire SetKeyValue / SetBrowseIndex / SetBrowseFilter / Find() sequence — you need none of those calls.

Options and approaches

Why not SetKeyValue and Find()?

Because on this file it does not work, and the failure is total rather than subtle. The documented attempts set every key field (PriceCodeRecord$ = "2" for a customer pricing record, PriceCode$, ItemCode$, CustomerNo$, ARDivisionNo$, CustomerPriceLevel$), tried the browse index as both KCUSTOMER and KITEMCUSTOMER, built the browse filter several different ways, and finally removed the browse calls altogether. Find() returned "not found" in every variation, against records that provably exist. If your script is built that way, do not keep tuning the filter — change the method.

ProvideX versus VBScript

The GetResultSets technique was first demonstrated in ProvideX (NEW("IM_PriceCode_svc", %sys_ss), the tick-syntax o'GetResultSets call, PAD() and $FE$ literals). None of that pastes into a User Defined Script: VBScript rejects the first line with OLE Error 1010 ("Expected Identifier"), then complains about the ProvideX-style results$ and $$ arguments. The VBScript translation above is the version that was tested in the ItemCode Post-Validate event — note in particular that VBScript has no PAD() function, which is why the padding is done with String(30, CHR(0)) and Left(), and the $FE$ end-of-range marker becomes CHR(254).

What doesn't work

  • Diagnosing with LastErrorMsg. After a GetResultSets call that finds nothing, the object's LastErrorMsg may read "There is no drop box information." That message simply means no records were found — it is the expected companion of a 0 return, not a script error. Branch on the return value (1 or 0) only.
  • Small syntax slips in the original approach. The first script set SetKeyValue("PriceCode", ...) without the trailing $ that marks a string field, and built its browse filter from two variables that were never assigned. Worth knowing if you are debugging someone else's script — but fixing them still leaves you on the Find() route that does not locate the record.
  • Expecting the item price code path to prove the customer path. A lookup with PriceCodeRecord$ = 1 (item price code) can succeed while the customer record (type 2) stays invisible to Find(). A working test against the wrong record type tells you nothing.

Affected versions

Documented on Sage 100 2014, with the final VBScript form tested on the SO_SalesOrderDetail ItemCode Post-Validate event. The IM_PriceCode file, its KCUSTOMER index, and the GetResultSets method are standard Business Object Interface machinery, but the confirmation behind this page is the 2014-era environment — test in your own version before rolling it out to order entry staff.

Prevention / best practice

  • Test pricing scripts against a customer/item pair you have verified in Data File Display and Maintenance first, so "no pricing" and "script broken" are never confused.
  • Keep the alert honest: the script detects that a customer pricing record exists. It does not change the price on the line — Sage's own pricing logic already applied whatever price the order carries.
  • If order takers only need the alert on some items or customers, filter inside the script after a positive result rather than complicating the lookup itself.

Related help

Still stuck? Send us a screenshot of the error, we will diagnose it for free.

Digit Masters has supported Sage 100 and Sage 300 since 1997. Send the screenshot through our contact page or to contact@digitmasters.com, or call (800) 965-4262.

Ready to Optimize Your Sage ERP?

Speak with a CPA-led Sage consultant. Free initial consultation — English or Chinese.

Get a Free Consultation