Showing posts with label D365 Code. Show all posts
Showing posts with label D365 Code. Show all posts

Thursday, 27 February 2020

Failed to execute query because no root data source on the form matches the root datasource on the query.

AX 2012 D365 FORM LOOKUP ERROR

It might be the case that you get the below error.
Failed to execute query because no root data source on the form matches the root datasource on the query.

In order to fix it make sure that the datasource used should be the same as defined .
For example.
        Query query = new Query();
        QueryBuildDataSource qbds = query.addDataSource(tableNum(InventSite));
       

        SysTableLookup sysTableLookup =  sysTableLookup::newParameters(tableNum(VendTable), _formControl);
        sysTableLookup.addLookupfield(fieldNum(InventSite, SiteId));
        sysTableLookup.addLookupfield(fieldNum(InventSite, Name));

        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();

In the above site lookup code you will get the same error because VendTable was used in the parameter instead of the inventsite so to fix , it should be defined as below.
  Query query = new Query();
        QueryBuildDataSource qbds = query.addDataSource(tableNum(InventSite));
       

        SysTableLookup sysTableLookup =  sysTableLookup::newParameters(tableNum(InventSite), _formControl);
        sysTableLookup.addLookupfield(fieldNum(InventSite, SiteId));
        sysTableLookup.addLookupfield(fieldNum(InventSite, Name));

        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();

thanks,
Vikas Mehta.

Tuesday, 26 November 2019

update method d365 eventhandlertable DataEventType::Updating D365 Code

Below is the event handler code to write at the table level for Updating any value.

Eventhandler code for updating a value at the table level .

[DataEventHandler(tablestr(FMRentalCharge),DataEventType::Updating),
     SuppressBPWarningAttribute('BPParameterNotUsed', 'This is not production code')]
    public static void FMRentalChargeUpdatingEvent(Common c, DataEventArgs e)
    {
        FMRentalCharge rentalCharge = c;
        FEDiscountEngine discountEngine;

        if (rentalCharge.orig().PerUnitAmount != rentalCharge.PerUnitAmount ||
            rentalCharge.orig().Quantity != rentalCharge.Quantity)
        {
            discountEngine = FMTotalsEngineBase::GetInstance() as FEDiscountEngine;
            if (discountEngine)
            {
                discountEngine.calculateChargeRate(rentalCharge);
            }
        }
    }

FMRentalChargeUpdatingEvent-> you can write any name .
SuppressBPWarningAttribute - > is optional ( it is for not using the e parameter of the dataeventargs.

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++  Introduction In our previous posts, we explored what Copilot can do o...