Sunday, October 23, 2016

How to get item's attribute value

We can get specific item's attribute using below code.

public static str dGetItemAttribute()
{
InventTable inventTableChk;
AttributeValueText getItemIdAttributeValue(ItemId   _itemId,
_attributeName)
{
EcoResProductAttributeValue ecoResProductAttributeValue;
AttributeValueText          attributeValueText;
InventTable                 InventTable;
EcoResAttribute             ecoResAttribute;
EcoResValue                 ecoResValue;
;
select Product from InventTable where InventTable.itemid == _itemId
    join RecId from ecoResProductAttributeValue
        where ecoResProductAttributeValue.Product == InventTable.Product
    join Name from ecoResAttribute
        where ecoResProductAttributeValue.Attribute == ecoResAttribute.RecId
            && ecoResAttribute.Name == _attributeName
    join ecoResValue
        where ecoResValue.RecId == ecoResProductAttributeValue.Value;

if (ecoResValue)
    attributeValueText = ecoResValue.value();
else
    attributeValueText = "Value? Product attribute";

return attributeValueText;
}
;
while select ItemId from InventTableChk
{
    // get value of attribute "2. Publish Price"
    info(strFmt('%1', getItemIdAttributeValue(inventTableChk.ItemId, '2. Publish Price')));
}
}

Friday, October 21, 2016

How to create AOT Map

Map can be created from AOT > Data Dictionary > Maps.

Using Map, we can access a single field from different tables with referencing single map field. So we can simplify the code.
Example, fields named PurchId in PurchTable and SalesId in SalesTable can be accessed by the name SalesPurchId.

For Map methods, we can override tables / xRecord methods, or add our own. To access the methods that only occurs in the Map (not in the table) we have to include the segment "varMap.JJK_Map::" because of the uniqueness of the method name.

public static str dTestMap()
{
//jjk_map is a map for purchTable and salesTable
JJK_Map map;
PurchTable purchTable;
SalesTable salesTable;
;
//mapMethod only exist in JJK_Map
map.mapMethod(); //no error will be thrown if no table buffer had been assigned to the map.
purchTable = PurchTable::find("PO0001");
map = purchTable;
map.mapMethod(); //error will be thrown because the buffer had been assigned to the map.
map.JJK_Map::mapMethod(); //we need to call the method with the segment
}

Thursday, October 20, 2016

How to get a message from infolog

To get the infolog in X++, you can use RetailTransactionService::getInfologMessages method:

public static str getInfoLog()
{
str         error;
int         fromLine = Global::infologLine();
info("this is an infolog");
error = RetailTransactionService::getInfologMessages(fromLine);
info(strfmt('error: %1', error));
}

or you can use below method.