Hi, when I press a button in the Asset Table form, I execute this code in order to show only the assets with a value of "0" in a table related with the Asset table.
I need to add a DataSource to the main DataSource of the form in order that I can filter the assets that have a value of "0" in the field "porcentajeAmortizacion" in the Table "AssetBookTable" that is related with AssetTable throught the field AssetId.
Well, all works fine the first time I press the button but the following time I press it the code don´t work because I am adding several times the same datasource to the AssetTable Ds.
How I can delete the datasource (AssetBook) in the original dataSource (AssetTable) at the beginning of the code so the second time I press the button the dataSource is not added for the second time?
Thanks
void selectRecords()
{
QueryBuildDatasource QBDS, QBDS2;
QueryBuildRange QBR;
;
QBDS = AssetTable_DS.query().dataSourceTable( tablenum(AssetTable));
QBDS.clearRanges();
QBDS.clearLinks();
QBDS2 = QBDS.addDataSource( tablenum(AssetBook));
QBDS2.addLink( fieldnum(AssetBook, AssetId), fieldnum(AssetTable, AssetId));
QBR = QBDS2.addRange(fieldNum(AssetBook, porcentajeamortizacion));
QBR.value("0");
AssetTable_DS.executeQuery();
}
0
Comments
You can try with this ...
After ClearLinks() ...
...
QBDS2 = AssetTable_DS.query().DataSourceTable(tablenum(AssetBook));
if (! QBDS2)
{
QBDS2 = QBDS.addDataSource( tablenum(AssetBook));
QBDS2.addLink( fieldnum(AssetBook, AssetId), fieldnum(AssetTable, AssetId));
}
QBR = QBDS2.findRange(fieldnum(AssetBook, porcentajeamortizacion));
if (! QBR)
QBR = QBDS2.addRange(fieldNum(AssetBook, porcentajeamortizacion));
QBR.value("0");
...
Good Luck, :whistle:
Mkz
A Dynamics Ax (Axapta) tricks site in Spanish language
Mkz
A Dynamics Ax (Axapta) tricks site in Spanish language
you should always check whether the datasource( AssetBook) is existed in form datasource first before adding it to the form datasource.
axapta here i come.