Ax 2012

generating CSV record with labels out of table fields

So pretty much this is the way to generate a line of csv file, getting value of the query table daa soucre field label values.

QueryRun qR;
Query _query;
Common record;

DictTable dictTable;
FieldId fieldId;
DictField dictField;

str output =””;
int x,y;

_query = new Query(“<nameOfTheQuery>”);
qR = new QueryRun(_query);
for(x = 1; x <= _query.dataSourceCount(); x++)
{

dictTable = new DictTable(_query.dataSourceNo(x).table());
for(y = 1; y <= _query.dataSourceNo(x).fields().fieldCount(); y++)
{
fieldId = _query.dataSourceNo(x).fields().field(y);
dictField = new DictField(dictTable.id(), fieldId);

if(dictField.arraySize() > 1)
{
continue;
}

output += strFmt(“%1%2”, dictField.label(), “|”);

}
}
info( output);
}

Ax 2012

Update help property if label exists

If you really need to copy existing label property to another property for example help text (that isn’t really best practice , I know 😦  ) this code can be used.

static void KindaBestPractiseThingy(Args _args)
{
#Properties
TreeNode fields = TreeNode::findNode(@”\Data Dictionary\Tables\<TableName>\Fields”);
TreeNodeIterator fieldsIterator;
TreeNode field;
str label;

fieldsIterator = fields.AOTiterator();
field = fieldsIterator.next();
while(field)
{
info(Field.AOTname());
Label = field.AOTgetProperty(#PropertyLabel);
info(Label);
Field.AOTsetProperty(#PropertyHelpText, Label);
field = fieldsIterator.next();
}
}