How can I delete a dataSource previously added?

pedroparra
Member Posts: 58
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();
}
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
-
Hola Pedro,
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:
Mkz0 -
Sorry for repeating, have some problem with posting.php
Mkz0 -
No problem. I already deleted the duplicates ;-)0
-
I'm totally agree with Manekaze.
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions