Command Lines

Prev Next

Command Lines in Document Customizer

Introduction

Command Lines is an advanced feature in Document Customizer that allows you to display data on documents that isn't directly available in the document's source table. This is particularly useful when you need to pull information from related tables in Business Central.

Unlike the "Using Table" method, Command Lines preserve the original text if no matching data is found in the linked table. For example, if no item translation exists for a specific item number, the system will print the item's default description instead.


When to Use Command Lines

Use Command Lines when:

  • You need to print data from a related table that isn't directly linked to the document

  • Multiple keys are required to link to another table (e.g., linking to both Payment Terms and Shipment Method in a header)

  • You want to avoid displaying unwanted values when the desired field is blank


Basic Syntax

The general formula for a Command Line is:

GetFieldValue(LookupRecord(This,A,'B','C','',''),D)

Where:

  • A = Table ID of the table you want to retrieve the field from

  • B = Unique Key Field(s) in the current document's table

  • C = Corresponding Unique Key Field(s) in the target table

  • D = Field ID of the field you want to display

⚠️ IMPORTANT: Do not use spaces in the formula, as this will cause an error.

Multiple Key Fields

If two fields are needed to create the link:

GetFieldValue(LookupRecord(This,A,'B1,B2','C1,C2','',''),D)

For more than two fields, extend the formula:

GetFieldValue(LookupRecord(This,A,'B1,B2,...,BN','C1,C2,...,CN','',''),D)

Key Functions

LookupRecord

Retrieves a record from a related table using a parent record.

LookupRecord(
  ParentRecIDText,           // Record ID of the parent record (use "This" for current record)
  LookupTableID,             // ID of the target table
  ParentLinkFields,          // Field numbers in the parent table
  LookupTableLinkFields,     // Field numbers in the lookup table
  LookupTableViewExpression, // Optional filter expression
  LookupTableViewValues      // Values for the filter expression
)

GetFieldValue

Retrieves a specific field value from a record using its Record ID and field number:

GetFieldValue(
  RecIDText,   // Record ID of the target record
  FieldNo      // Field number to retrieve
)

💡 Tip: Use the keyword This to refer to the current record.


Step-by-Step Process

Step 1: Find Required Table and Field IDs

Use the Page Inspection feature in Business Central:

  • Keyboard shortcut: Alt+Shift+F1

  • This shows the table used for the current page, available fields, and their IDs

Step 2: Identify the Required Information

Note the following:

Parameter

Description

A

Table ID of the source table containing your desired field

B

Unique Key Field ID(s) in the document's table

C

Corresponding Unique Key Field ID(s) in the target table

D

Field ID of the field you want to display

Step 3: Build Your Command Line

Construct the formula using the values gathered:

GetFieldValue(LookupRecord(This,A,'B','C','',''),D)

Step 4: Add to Document Customizer

  1. Create a new column as you normally would

  2. Set Table No. to match other columns for the document

  3. Set Field to 0 (since the table and field are defined in the command line)

  4. Optionally enable "Blank caption if no value"

  5. Add an appropriate Caption

  6. Enter your formula in the Command Line field


Practical Example: Outstanding Quantity on Posted Sales Shipment

Goal: Display the Outstanding Quantity from a Sales Order on the Posted Sales Shipment document.

Challenge: The Outstanding Quantity field exists in the Sales Line table (37), not in the Sales Shipment Line table.

Solution

We need two unique identifiers:

  • Document Number - connects the Posted Sales Shipment to the Sales Order

  • Line Number - connects specific lines between documents

Values identified:

  • A = 37 (Sales Line table)

  • B = 65,66 (Document Number and Line Number in Sales Shipment Line)

  • C = 3,4 (Document Number and Line Number in Sales Line)

  • D = 16 (Outstanding Quantity field)

Final Command Line:

GetFieldValue(LookupRecord(This,37,'65,66','3,4','',''),16)

Adding Filters

To filter records in the lookup table, use this syntax:

GetFieldValue(LookupRecord(This,A,'B','C','FieldE=1(%1)','F'),D)

Where:

  • E = Field ID to filter on

  • F = Value to filter for

Example - Filter by Location Code "MAIN":

GetFieldValue(LookupRecord(This,37,'65,66','3,4','Field28=1(%1)','MAIN'),16)

Nested Command Lines

Command Lines can be nested within other Command Lines for complex lookups:

GetFieldValue(LookupRecord(This,A,'B','C','',GetFieldValue(LookupRecord(This,AA,'BB','CC','',''),DD)),D)

Example: Item Translation with Customer Language

This retrieves a translated item description based on the customer's language:

GetFieldValue(LookupRecord(This,30,'6,5402','1,5400','Field2=1(%1)',GetFieldValue(LookupRecord(This,36,'3','3','',''),41)),3)

How it works:

  1. Inner lookup: Gets the Sell-to Customer No. from the Sales Header (Table 36)

  2. Outer lookup: Uses that customer number to find the Item Translation (Table 30) for the current item

  3. Final retrieval: Returns the translated description (Field 3)


Common Examples

Document Header Examples (Table 112)

Purpose

Command Line

Job No. on first sales line

GetFieldValue(LookupRecord(This,113,'3','3','',''),45)

Job Name from first line

GetFieldValue(LookupRecord(LookupRecord(This,113,'3','3','',''),167,'45',1,'',''),3)

Payment Method Code

GetFieldValue(LookupRecord(This,466,'104','1','Field2=1(%1)',GetFieldValue(LookupRecord(This,112,'3','3','',''),41)),3)

Other Common Lookups

Purpose

Command Line

Dimension Value (e.g., "PROJECT")

GetFieldValue(LookupRecord(LookupRecord(This,480,'480','1','Field2=1(%1)','PROJECT'),349,'2,3','1,2','',''),3)

Barcode/EAN from Item Cross Reference

GetFieldValue(LookupRecord(This,5717,'6,5402,5407','1,2,3','Field4=1(%1)','3'),6)

Country of Origin

GetFieldValue(LookupRecord(LookupRecord(This,27,'6','1','',''),9,'95','1','',''),2)

Tariff No. Name

GetFieldValue(LookupRecord(LookupRecord(This,27,'6','1','',''),260,'47','1','',''),2)

Length (from T5404)

GetFieldValue(LookupRecord(This,5404,'6,13','1,2','',''),7300)

Job Task No. from T113

GetFieldValue(LookupRecord(This,1001,'45,1001','1,2','',''),3)

External Document No. (T36)

GetFieldValue(LookupRecord(This,36,'4,6','1,3','',''),100)

Shipment Method on Sales Shipment

GetFieldValue(LookupRecord(This,463,'27','1','Field2=1(%1)',GetFieldValue(LookupRecord(This,110,'3','3','',''),41)),3)

Item Translation Examples

From Table 111:

GetFieldValue(LookupRecord(This,30,'6,5402','1,5400','Field2=1(%1)',GetFieldValue(LookupRecord(This,110,'3','3','',''),41)),3)

Customer Item Cross Reference (Tables 37 and 113):

GetFieldValue(LookupRecord(This,5777,'6,5402,5407,2','1,2,3,5','Field4=1(%1)','1'),6)

Rounding Numbers

You can use the Round function in Command Lines to control how numbers are displayed on your documents.

Round Syntax

Round(precision,'direction')

Where:

  • precision = The decimal precision for rounding

  • direction (optional) = '>' to round up, '<' to round down

Rounding Examples

Command

Description

Example Result

Round(1)

Round to nearest whole number

3.7 → 4

Round(1,'>')

Round up to nearest whole number

3.2 → 4

Round(1,'<')

Round down to nearest whole number

3.9 → 3

Round(0.01)

Round to 2 decimals

3.456 → 3.46

Round(0.001)

Round to 3 decimals

3.4567 → 3.457

Round(0.01,'>')

Round up to 2 decimals

3.441 → 3.45

Round(0.01,'<')

Round down to 2 decimals

3.449 → 3.44

Using Round with Command Lines

You can combine the Round function with GetFieldValue and LookupRecord to round values retrieved from related tables:

Round(GetFieldValue(LookupRecord(This,A,'B','C','',''),D),0.01)

This retrieves a field value and rounds it to 2 decimal places.


Best Practices

Avoid Special Characters

⚠️ Warning: Using special characters (such as &, %, #, @, etc.) in field values can cause lookup failures or unexpected behavior.

Avoid special characters in any field values referenced in:

  • ParentLinkFields

  • LookupTableViewExpression

  • LookupTableViewValues

Command Line vs. Using Table/Using Field

Feature

Command Line

Using Table/Using Field

Field column value

Can be set to 0

Must specify the linking field

Blank field handling

Shows nothing if target field is blank

Shows the linking field value

Flexibility

High - full control over lookups

Limited to simple lookups

Complexity

More complex syntax

Simpler to set up

Recommendation: Use Command Lines when you want to avoid displaying unintended values when the desired field is blank.


Troubleshooting

Issue

Possible Cause

Solution

Error when using command line

Spaces in formula

Remove all spaces from the formula

Lookup returns wrong data

Incorrect field IDs

Verify field IDs using Page Inspection (Alt+Shift+F1)

No data returned

Missing link fields

Ensure all required key fields are included

Unexpected characters displayed

Special characters in field values

Remove special characters from source data


Summary

Command Lines provide a powerful way to display data from related tables on your Business Central documents. While the syntax may seem complex at first, following the structured approach outlined in this guide will help you create effective lookups for your document customization needs.

Key takeaways:

  1. Always use Page Inspection to find correct table and field IDs

  2. Never use spaces in your formulas

  3. Use This to reference the current record

  4. Nested lookups can solve complex data retrieval scenarios

  5. Avoid special characters in field values used for lookups