How can I delete a dataSource previously added?

pedroparrapedroparra Member Posts: 58
edited 2006-02-01 in Dynamics AX
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();
}

Comments

  • ManekazeManekaze Member Posts: 6
    Hola Pedro, :wink:

    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
    http://www.TrucosAx.com
    A Dynamics Ax (Axapta) tricks site in Spanish language :)
  • ManekazeManekaze Member Posts: 6
    Sorry for repeating, have some problem with posting.php :(
    Mkz
    http://www.TrucosAx.com
    A Dynamics Ax (Axapta) tricks site in Spanish language :)
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
    No problem. I already deleted the duplicates ;-)
  • vulamvulam Member Posts: 24
    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. :D
Sign In or Register to comment.