Friday, April 15, 2011

Creating transfer order through X++ code

To create a transfer oder via a code:

inventTransferTable.clear();
inventTransferTable.initValue();
numberSequenceReference = InventParameters::numRefTransferId();
numberSeq =
numberSeq::newGetNumFromCode(numberSequenceReference.NumberSequence);
inventTransferTable.TransferId = numberSeq.num();
inventTransferTable.InventLocationIdFrom = fromloc;
inventTransferTable.modifiedField(fieldNum(InventTransferTable,InventLocationIdFrom));
inventTransferTable.InventLocationIdTo = toloc;
inventTransferTable.modifiedField(fieldNum(InventTransferTable,InventLocationIdTo));
inventTransferTable.TransferStatus = InventTransferStatus::Created;
inventTransferTable.insert();


inventTransferLine.clear();
inventTransferLine.initFromInventTransferTable(inventTransferTable,
NoYes::Yes);
nventTransferLine.ItemId = item;
inventTransferLine.initFromInventTable(InventTable::find(item));
inventTransferLine.QtyTransfer = qty_ship;
inventTransferLine.QtyShipNow = 0;
inventTransferLine.QtyReceiveNow = 0;
inventTransferLine.insert();

Also set the two fields:

QtyRemainShip and QtyRemainReceive to the value of QtyTransfer when you create the line.

Wednesday, April 6, 2011

Display all/specific AOT tables in a lookup

For displaying all/specific AOT objects like tables in the lookup control, we need to iterate the UtilidElements table with our desired criteria.

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

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

    nameQBR = queryBuildDataSource.addRange(fieldnum(UtilidElements,
    name));
    nameQBR.value('Cust*');

    typeQBR = queryBuildDataSource.addRange(fieldnum(UtilidElements, recordType));
    typeQBR.value(SysQuery::value(UtilElementType::Table));

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

Friday, April 1, 2011

Count total number of records

To count number of records in a query, you just need check it through SysQuery::countTotal(QueryRun) and if the query have more than one data sources use SysQuery::countLoops(QueryRun) instead of SysQuery::countTotal(QueryRun).

Happy Daxing