In X++, a table ID is a unique identifier for a table in the application's database. It is a numerical value that is assigned to each table when the table is created. The table ID is used to identify the table when performing database operations such as selecting, inserting, or deleting records from the table.
A field ID is a unique identifier for a field within a table in the application's database. It is a numerical value that is assigned to each field when the field is added to the table. The field ID is used to identify the field when performing operations such as selecting or updating the field's value.
Both table IDs and field IDs can be used in X++ to reference tables and fields in a generic way, allowing you to write code that can work with any table or field in the application's database. This can be useful when you want to write code that is flexible and can be used with multiple tables or fields without having to hard-code the table or field names.
To use a table ID or field ID in X++, you can use the tablenum and fieldnum functions, respectively. These functions take the name of the table or field as an input and return the corresponding table ID or field ID.
For example, to retrieve the table ID for the "CustTable" table, you can use the following code:
TableId tableId;
tableId = tablenum(CustTable);
And to retrieve the field ID for the "AccountNum" field in the "CustTable" table, you can use the following code:
FieldId fieldId;
fieldId = fieldnum(CustTable, AccountNum);
Example:
tableId tabId;
fieldId fieldId;
select tabId
where tabId.TableName == 'CustTable';
select fieldId
where fieldId.TableId == tabId && fieldId.FieldName == 'Name';
while select * from tabId
{
info(tabId.(fieldId));
}