问题
When AX generates forms and grids, all the lookups are populated properly, but the ID of the lookup item is displayed in the form. The only way to see values that make sense is to click on the field--not really ideal. Is there a way to display the lookup value in the form instead of the id number behind it?
I would like the "tableB" form to display the tableA_value instead of the tableA_id.
tableA
- tableA_id (int - unique)
- tableA_value (string - non-unique)
tableB
- tableB_id (int - unique)
- tableA_id (int - relation to tableA)
- tableB_datafields (misc)
Thanks
回答1:
Couldn't find a way to change the value of the lookup itself, so I put a static field next to it that updates any time the lookup is changed. Here's how I ended up doing it:
Display Method on Table A:
display [datatype] lookupName(tableA _tableA)
{
;
return tableB::find(_tableA.[tableA id column]).[tableB string column];
}
Find Method on Table B:
static tableB find([datatype] [lookup variable], boolean _forUpdate = false,
ConcurrencyModel _concurrencyModel = ConcurrencyModel::Auto)
{
[TableB] [tableB];
if ([lookup variable])
{
if (_forUpdate)
{
tableB.selectForUpdate(_forUpdate);
if (_concurrencyModel != ConcurrencyModel::Auto)
{
tableB.concurrencyModel(_concurrencyModel);
}
}
select firstonly tableB
where tableB.[lookup column] == [lookup variable];
}
return tableB;
}
Added both table A and B as datasources for the form.
Added a string field to the form.
Set table A as the DataSource for the field and lookupName as the DataMethod.
Added a modified method to the lookup field to cause the static field to update:
element.redraw();
Hope this helps someone.
来源:https://stackoverflow.com/questions/1716694/axapta-lookup-field-display-the-string-value-instead-of-the-id