Select a record from a table when you only have the tableId
The following code can provide you a generic way to update a table when you only have the tableId.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public Common findRecord(TableId _tableId, RecId _recId, Boolean _forUpdate = false) { Common common; DictTable dictTable; ; dictTable = new DictTable(_tableId); common = dictTable.makeRecord(); common.selectForUpdate(_forUpdate); select common where common.RecId == _recId; return common; } |
If you want, you can even update fields in this common record. You can Access/edit these fields by using their Name or FieldNum. The method below will update a specific field in a table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public void updateValue(TableId _tableId, RecId _recId, str _field, AnyType _value) { Common common; Int fieldId; ; ttsbegin; common = findRecord(_tableId, _recId, true); fieldId = fieldname2id(_tableId,_field); if (fieldId && _value) { common.(fieldId) = _value; common.update(); } ttscommit; } |
Tags: Ax 5.0 (2009), Data Types, DictTable, Dynamics AX, Programming, Tips & Tricks, X++
This entry was posted on Thursday, July 16th, 2009 at 16:34 and is filed under Dynamics AX. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


August 27th, 2009 at 00:02
Selecionando registros quando você só tem o TableID. by Dynamics AXBR says:[...] Fonte: http://www.doens.be/2009/07/select-a-record-from-a-table-when-you-only-have-the-tableid/ [...]