Financial dimensions with AX 2012 collected in RecId fields and that RecId referes a couple of tables so it's a bit complicated. Fortunately there is a class for make it easy:
DimensionProvider dimProvider = new DimensionProvider();
dimProvider.addOrderByAttribute(BorAXJournalTrans_DS.query(),BorAXJournalTrans_DS.query().dataSourceNo(1).name(),
FieldStr(BorAXJournalTrans,DefaultDimension),
DimensionComponent::DimensionAttribute,SortOrder::Ascending,
"Department");
BorAXJournalTrans_DS.executeQuery();
If you don't want to use that class alternate is:
RecId depRecId = 5637152827; //RecId value of department dimension at DimensionAttribute table
BorAXJournalTrans boraxJournalTrans;
DimensionAttributeValueSet dimensionAttributeValueSet;
DimensionAttributeValueSetItem dimensionAttributeValueSetItem;
DimensionAttributeValue dimensionAttributeValue;
DimensionAttribute dimensionAttribute;
while SELECT firstOnly10 borAXJournalTrans
ORDER BY DimensionAttributeValueSetItem.DisplayValue
JOIN dimensionAttributeValueSet
where borAXJournalTrans.DefaultDimension == dimensionAttributeValueSet.RecId
JOIN dimensionAttributeValueSetItem
where dimensionAttributeValueSet.RecId == dimensionAttributeValueSetItem.DimensionAttributeValueSet
JOIN dimensionAttributeValue
where dimensionAttributeValueSetItem.DimensionAttributeValue == dimensionAttributeValue.RecId
JOIN dimensionAttribute
where dimensionAttributeValue.DimensionAttribute == dimensionAttribute.RecId &&
dimensionAttribute.RecId == depRecId
{
info(dimensionAttributeValueSetItem.DisplayValue);
}