Example: create expression to be used in data display
In the following example we will construct an example of how to create you own expression for data display, used in Data Sources/fields, List Designs/Cells, Display Override and in print template fields
In the following code, we will create a class that will end up as an expression usable in the Mobile WMS client to setup data displayed for the device.
The expression will take an item ID, or a record with an item ID field, and return a string containing the companies, where the given item ID has been released.
To achieve this, the following class can be written:
/// <summary>
/// An expression class used to retrieve where the item is released.
/// </summary>
[MobDescription("An expression class used to retrieve where the item is released. Takes either item ID or a table with a ItemId field")]
class MobExpressionsItemReleasedInCompanies extends MobExpressions
{
public str processExpressionCommon(Common _common)
{
DictTable dt = new DictTable(_common.tableId);
FieldId fieldId = (dt != null ? dt.fieldName2Id(identifierStr(ItemId)) : 0);
return this.processExpressionValue(fieldId ? _common.(fieldId) : '');
}
public str processExpressionValue(str _value)
{
str returnStr = '';
InventTable iTable = InventTable::Find(_value);
SetEnumerator sEnum;
if (!iTable)
{
return returnStr;
}
sEnum = iTable.Product().getCompaniesWhereReleased().getEnumerator();
while (sEnum.moveNext())
{
returnStr += (returnStr ? ', ' : '') + sEnum.current();
}
return returnStr;
}
}
Things of Note:
There are 2 methods in this class, one that takes a record, and returns an answer, and one that takes a string value, and returns an answer. These two methods are mandatory to implement when using the expression classes, but if either are not applicable, the method can be augmented with a [SysObsolete] attribute, whereas the system will ignore that option.
The class is called “MobExpressionsItemReleasedInCompanies
", which means, that you can reference this in the User interface using “ItemReleasedInCompanies”.
When referencing this expression you can use ItemReleasedInCompanies([record]) to pass the active record, and ItemReleasedInCompanies([value]) to pass a specific field.
in the Data Sources Fields setup, the expressions would be passed like this:
You read more about using expressions here