SAP Business One formatted searches (FMS): $[$38.1.0] syntax, 7 practical examples and auto-refresh
By Zain Abbas, Kodenova · Updated
What a formatted search is
A formatted search, usually called FMS, is a saved query linked to one field on one form. When it runs, SAP Business One either writes the result into the field or shows a list for the user to pick from.
Users love them because they remove typing. Developers like them because no add-on is needed. You can fill a line UDF with the item’s foreign name, show stock in the line warehouse, or offer a dropdown from a user-defined table.
If you want to skip the syntax work, our formatted search builder writes the query for you.
The syntax
There are two ways to read values from the open form.
| Form | Example | When to use |
|---|---|---|
$[$Item.Column.Type] | $[$38.1.0] | Reads the field by its position on the form. Works across similar documents. |
$[TABLE.Field] | $[OINV.CardCode] | Reads by table and field name. Only works on forms based on that table. |
In the first form:
- Item is the form item index. On sales and purchasing documents,
38is the lines matrix and4is the customer or vendor code. - Column is the matrix column. Use
0for header fields. - Type controls how the value comes back:
0returns the value as is. Use it for codes, text and document numbers.NUMBERreturns a number without the currency or unit. Use it for maths.CURRENCYreturns only the currency symbol or unit of measure.DATEreturns a date you can add days to.
SAP’s own guide recommends the index form, because $[$4.0.0] works on any marketing document, while $[OINV.CardCode] only works on A/R invoices.
User-defined fields use their name as the column: $[$38.U_Discount.NUMBER].
Don’t want to look up item and column IDs by hand? The formatted search builder writes the variable for the field you pick.
Quick reference
| Variable | What it returns |
|---|---|
$[$38.1.0] | Item code of the current row: item 38 is the lines matrix, column 1 the item number, and 0 means the field holds a single value. |
$[$38.17.NUMBER] | The number of a price or total field without the currency symbol, ready for maths. |
$[$38.17.CURRENCY] | Only the currency symbol (or unit of measure) of that field. |
$[$10.0.DATE] | A header date you can calculate with, for example $[$10.0.DATE] + 20. Header fields use column 0. |
$[$4.0.0] | The customer or vendor code on any sales or purchasing document. |
$[ORDR.CardCode], $[RDR1.ItemCode] | Table and field name. Works only on the window based on that table (here the sales order). |
$[$38.U_Discount.NUMBER] | A row user-defined field: always write the U_ prefix, or SAP B1 returns error -1003. |
Item and column numbers can differ between versions and forms. Check them with View → System Information before you rely on a number.
How to find item and column IDs
- In SAP Business One, open View > System Information.
- Open the form and hover over the field.
- Read the status bar at the bottom. It shows the item, the column and, for database fields, the table and field name.
Check every ID on your own version and form. Column numbers can differ between document types and localisations. Our SAP B1 table reference helps with the table and field names.
How to attach a formatted search
- Save your query in the Query Manager, ideally in a category called “FMS”.
- Open the target form and click into the field.
- Press Alt+Shift+F2. The formatted search window opens.
- Choose Search in Existing User-Defined Values according to Saved Query and select your query.
- Decide when it runs:
- No auto refresh: the user presses Shift+F2 or clicks the magnifier.
- Auto Refresh When Field Changes: pick the trigger field, for example the item code. The query runs when the user leaves that field.
- Display Saved Values: keeps the value stored on the document instead of re-running the query every time the document is opened.
- Click Update and test on a new document.
SAP’s guide also lists a “Refresh Regularly” option. It warns to use it sparingly because it can slow forms and change saved documents when they are browsed.
7 practical examples
All examples use SQL Server syntax. The HANA notes come after.
1. Item field on a line. Foreign name of the line item into a line UDF (table OITM).
SELECT T0.FrgnName
FROM OITM T0
WHERE T0.ItemCode = $[$38.1.0]
2. Business partner field on the header. Available credit for the selected customer (table OCRD).
SELECT T0.CreditLine - T0.Balance
FROM OCRD T0
WHERE T0.CardCode = $[$4.0.0]
3. Stock in the line warehouse. Column 24 is the warehouse on many document forms. Confirm it with System Information. Stock per warehouse is in OITW.
SELECT T0.OnHand
FROM OITW T0
WHERE T0.ItemCode = $[$38.1.0]
AND T0.WhsCode = $[$38.24.0]
4. Last price sold to this customer. Useful as a check next to the price column (A/R invoices in OINV).
SELECT TOP 1 T1.Price
FROM OINV T0
INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T0.CardCode = $[$4.0.0]
AND T1.ItemCode = $[$38.1.0]
AND T0.CANCELED = 'N'
ORDER BY T0.DocDate DESC, T0.DocEntry DESC
5. Line weight. Sales weight per unit times the line quantity (column 11).
SELECT T0.SWeight1 * $[$38.11.NUMBER]
FROM OITM T0
WHERE T0.ItemCode = $[$38.1.0]
6. Dropdown from a user-defined table. Returning two columns gives the user a list to choose from.
SELECT T0.Code, T0.Name
FROM [@REGIONS] T0
ORDER BY T0.Name
7. Today’s date. Fills a date UDF when the document is created.
SELECT GETDATE()
HANA differences
On SAP Business One for HANA, the logic stays the same but the SQL changes:
- Put table and column names in double quotes:
T0."ItemCode","@REGIONS". - UDF names inside the variable also need quotes:
$[$38."U_Discount".NUMBER]. - A
SELECTwithout a table needsFROM DUMMY. - Replace SQL Server functions:
GETDATE()becomesCURRENT_DATE,ISNULLbecomesIFNULL.
Example 7 on HANA:
SELECT CURRENT_DATE FROM DUMMY
Example 1 on HANA:
SELECT T0."FrgnName"
FROM OITM T0
WHERE T0."ItemCode" = $[$38.1.0]
If you are moving many queries, paste them into our SQL to HANA converter and then test each one.
Common formatted search errors and how to fix them
| Symptom | Usual cause | Fix |
|---|---|---|
| Internal error (-1003) occurred when the search runs | The SQL failed when SAP Business One ran it: a syntax error, a missing bracket, or a field reference that does not resolve | Run the query in the Query Manager, or run the translated SQL in SQL Server Management Studio, and fix the error it reports. Then check each $[...] reference with View > System Information. |
| The query works on SQL Server but fails on HANA | Unquoted mixed-case column names, or a SELECT without a table | Put table and column names in double quotes and add FROM DUMMY. See HANA differences. |
| A user-defined field is not found | The field was written without its U_ prefix | Always write the full name, for example $[$38.U_Discount.NUMBER]. |
| The value does not change when the trigger field changes | Auto Refresh When Field Changes is off, or points at the wrong field | Tick Auto Refresh and pick the field that should trigger the query. Without it, the query runs only on Shift+F2. |
| The value is recalculated when you reopen an old document, or never updates | The wrong refresh option is chosen | Display Saved Values shows what was saved with the document. Refresh Regularly re-runs the query every time you browse to the document, and SAP warns it can slow documents down and change values you did not mean to change. |
Auto Refresh also does nothing on fields that can no longer be changed, such as the item number on an existing delivery.
Performance tips
- Line-level searches multiply. A search that auto-refreshes on the item code runs once per line. On a 200-line order, that is 200 queries. Add three such searches and users will feel it.
- Filter on keys. Query by
ItemCode,CardCode,DocEntry. AvoidLIKE '%x%'and functions on columns in theWHEREclause. - Avoid heavy joins on document tables. Example 4 scans invoice history. Fine for a few hundred thousand lines, slow for millions. Consider an index or a summary table.
- Prefer on-demand for rare needs. If users need a value only now and then, leave auto refresh off and let them press Shift+F2.
- Use Display Saved Values for anything that should not change after the document is saved.
When to use something else
A formatted search fills fields. It does not enforce rules. A user can overwrite the value, and imports through DI API or Service Layer do not run it.
- Use the transaction notification stored procedure (
SBO_SP_TransactionNotification) when a rule must always hold, for example “no invoice without a cost centre” or “price cannot be below cost”. It blocks the save, whatever the source. - Use an add-on when you need new screens, buttons, calls to external APIs, or logic that depends on many fields at once.
- Keep FMS for defaults, lookups and pick lists that help the user type less.
Formatted searches fill fields while people type; for reporting on the same data, see how to build an SAP Business One dashboard without Power BI.
Ready to build one? Open the formatted search builder, pick your form and field, and copy the query. If your documents are slow or you need rules that FMS cannot enforce, contact us and we will look at your setup.
Sources
- SAP: How to Define and Use Formatted Search (SAP Business One how-to guide, PDF)
- SAP: How to Define and Use Formatted Searches (hosted by Vision33)
- SAP Community: Formatted search to calculate discount on SAP B1 HANA
- SAP Community: Internal error (-1003) occurred [Message 131-183] when executing a formatted search
- Packt: Working with User-Defined Values in SAP Business One
Related services
Frequently asked questions
What does $[$38.1.0] mean in SAP Business One?
It reads a value from the open form. 38 is the item index of the document lines matrix, 1 is the column (Item No.) and 0 is the type, which returns the plain value. So $[$38.1.0] is the item code on the current line.
What is the difference between 0, NUMBER and DATE in a formatted search?
0 returns the field value as it is, which suits codes and text. NUMBER returns a numeric value without the currency or unit, so you can calculate with it. DATE returns a date you can use in date arithmetic.
How do I find the item and column number of a field?
Turn on View > System Information, then hover over the field. The status bar shows the item number, the column and, for database fields, the table and field name.
Do formatted searches work on SAP Business One for HANA?
Yes, but the SQL must follow HANA rules. Put table and column names in double quotes, use FROM DUMMY when you select a value without a table, and replace SQL Server functions such as GETDATE() with HANA ones such as CURRENT_DATE.
Why does my formatted search give Internal error (-1003)?
In practice it means the SQL failed when SAP Business One ran it: a syntax error, a wrong field reference or a user-defined field written without U_. Run the same query in the Query Manager, or run the translated SQL in SQL Server Management Studio, read the real error and fix it there. Then check every $[...] reference with View > System Information.
Why are my documents slow after adding formatted searches?
Each formatted search runs a query. One that auto-refreshes on every line, or is set to refresh regularly, runs many times per document. Keep line-level searches few, index-friendly and on demand where possible.
Ready to get started?
Tell us what you need. You get a clear technical answer, a fixed scope and a price, usually within 24 hours.
