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.

Wednesday, August 17, 2016

How to create Lookups on Dialog: SysTableLookup and registerOverrideMethod

We can create a lookup in dialog without hardcode the field object (Fld1_1_lookup) using the form control's registerOverride method.

SysTableLookup can be used in dialogs to create custom lookups.
control.registerOverrideMethod can be used to register the methods to override by an object.
Here is the example which shows basic usage of both. We will create a dialog and get a lookup of account numbers on a control.

Tuesday, August 2, 2016

How to deserialize xml into table from code

class JJK_XMLDeserializer
{
Common common;
str xmlStr;
Integer tableLevel;
}

public str deserialize()
{
XmlTextReader xmlTextReader; int level = 0;
str fieldName;
;

xmlTextReader = XmlTextReader::newXml(xmlStr, true);

while(xmlTextReader.read())
{
switch (xmlTextReader.NodeType())
{
case XmlNodeType::Element: // The node is an element.
//print ("<" + xmlTextReader.Name() + ">");
level++;
if ( level == tableLevel )
{
common.clear();
}
fieldName = xmlTextReader.name();
break;
case XmlNodeType::Text: //Display the text in each element.
//print (xmlTextReader.Value());
this.processRecord(common, fieldName, xmlTextReader.value());
break;
case XmlNodeType::EndElement: //Display the end of the element.
//print ("</" + xmlTextReader.Name() + ">");
level--;
if ( level==tableLevel-1 )
{
common.insert();
common.clear();
}
break;
}
}
return "";
}

public void processRecord(Common _common = common, str _fieldName = '', str _fieldValue = '')
{
DictTable dTable = new DictTable(_common.TableId);
DictField dField;
int i, fieldId;
str value;
;
// Loop through all the fields in the record
for (i=1; i<=dTable.fieldCnt(); i++)
{
// Get the fieldId from the field-count
fieldId = dTable.fieldCnt2Id(i);

// Find the DictField object that matches the fieldId
dField = dTable.fieldObject(fieldId);

// Skip system fields
if (dField.isSystem())
continue;

if ( dField.name()!=_fieldName )
{
continue;
}
// Convert values to string. I have just added
// a couple of conversion as an example.
// Use tableName.(fieldId) instead of fieldname
// to set the content to the field.

switch (dField.baseType())
{
case Types::Int64 :
_common.(fieldId) = str2int64(_fieldValue);
break;
case Types::Integer :
_common.(fieldId) = str2int(_fieldValue);
break;
default :
_common.(fieldId) = _fieldValue;
break;
}
return;
}
}

Test string:
'<xml >'
+'<JJK_XMLAttachment action="create">'
+'<RefRecId>555</RefRecId>'
+'<RefTableId>555</RefTableId>'
+'<XMLDocument>Test</XMLDocument>'
+'</JJK_XMLAttachment>'
+'<JJK_XMLAttachment action="create">'
+'<RefRecId>222</RefRecId>'
+'<RefTableId>222</RefTableId>'
+'<XMLDocument>Test222</XMLDocument>'
+'</JJK_XMLAttachment>'
+'</xml>';

Friday, May 20, 2016

Assembly containing type %1 is not referenced.

When AIF / web services / dll references cannot be called (with error: Assembly containing type %1 is not referenced.) Then you need to give AOS user an access to "Program Files\Microsoft Dynamics AX\60\[YOUR AOS NAME]\bin\VSAssemblies" folder.

After that, restart the AOS. If the error still persist then do the full compile.

Tuesday, March 22, 2016

How to create multiple values in query range

You can create multiple values in query range from x++, where the code is:

QueryBuildDataSource qbds = q.dataSourceTable(TableId);
QueryBuildRange qbr;
while (...)
{
    qbr = qbds.addRange(fieldNum(TableId, FieldId));    qbr.value(queryValue(TableId.fieldId));
}
QueryBuildRange qbr = q.dataSourceTable(TableId).addRange(fieldNum(TableId, FieldId));
container c;
while (...)
{
    c+= queryValue(TableId.FieldId);
}
qbr.value(con2str(c));

Tuesday, March 15, 2016

How to override form datasource with another query

You can override form datasource with another (filtered) query.

You can put the code in datasource.executeQuery()

public void executeQuery()
{
    FormDataSource fds;
    ;
    //info(strFmt('1--%1', this.query().toString()));
    queryClass.executeQuery();
 
    fds = this.formRun().dataSource();
    fds.query(queryClass.parmQuery());
 
    //info(strFmt('1.1--%1', fds.query().toString()));
    //info(strFmt('2--%1', queryClass.parmQuery().toString()));
    super();
}

Where the "queryClass" is a class that create a filtered query.

Wednesday, March 9, 2016

How to comparing 2 field in AOT Query

The rules for creating query range value expressions are:
  • Enclose the whole expression in parentheses.
  • Enclose all subexpressions in parentheses.
  • Use the relational and logical operators available in X++.
  • Only use field names from the range's data source.
  • Use the dataSource.field notation for fields from other data sources in the query.


Tuesday, March 8, 2016

How to open FilePath EDT on form

If the filepath dialog is not opening on Form, U have to add below method on form (AOT > MyForm > Method > filePathLookupTitle)

public str filePathLookupTitle()
{
    return 'Import folder';
}

Sunday, March 6, 2016

How to create AOT object lookup

static void lookupAOTTables(FormStringControl _ctrl)
{
   SysTableLookup sysTableLookup =   SysTableLookup::newParameters(tablenum(UtilidElements), _ctrl);
   Query query = new Query();
   QueryBuildDataSource queryBuildDataSource;
   QueryBuildRange qbrType;
   ;
   sysTableLookup.addLookupfield(fieldnum(UtilidElements, Id));
   sysTableLookup.addLookupfield(fieldnum(UtilidElements, Name));

   queryBuildDataSource = query.addDataSource(tablenum(UtilidElements));

   qbrType= queryBuildDataSource.addRange(fieldnum(UtilidElements, RecordType));
   qbrType.value(SysQuery::value(UtilElementType::Table));

   sysTableLookup.parmQuery(query);
   sysTableLookup.performFormLookup();
}

Saturday, February 27, 2016

Cara Membuat Lookup Dimension di report contract

Didalam artikel ini kita akan membahas bagaimana cara membuat lookup untuk memilih Dimension attribute pada report parameter.

Pertama-tama kita harus membuat UIBuilder class  yang akan dipakai oleh SSRS Report kita. Lalu di dalam class tersebut kita buat sebuah method lookup dimension.

How to add SalesParmUpdate.specQty

First add a new element in SalesUpdate enum.

example: add JJK_TestElement in SalesUpdate enum.
After that add a logic in SalesQuantity class for the new added enum. There are 2 method in SalesQuantity class that can be use to calculate qty, which are calcQtySales and calcQtyInvent.

Friday, February 12, 2016

Cara men-set dialogField dari Form

Untuk men-set value pada dialogField dari Args nya form, dapat menggunakan method: pack() dan unpack().