web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Form Datasource Extension does only return Alternative Datasource record after refresh.

(1) ShareShare
ReportReport
Posted on by 230
Good day all!
 
I have extended the ReqTransOverview form (Net requirements). I have made a custom view, which shows all inventory status and stock levels of the opened item.
 
This view needs to be restricted by some ranges, which I need to retrieve from the Reqtrans table, which is an alternative datasource of the ReqTransOverview form:
 
 
To realise this, I have created the following handler:
[FormDataSourceEventHandler(formDataSourceStr(ReqTransOverview, ELCWDItemStockOverView), FormDataSourceEventType::QueryExecuting)]
public static void ELCWDItemStockOverView_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)
{        
    FormRun formRun;
    FormDataSource  reqTransDS;
    ReqTrans reqTrans;

   
    reqTransDS  = sender.formRun().dataSource(formDataSourceStr(ReqTransOverview, ReqTrans));

    reqTrans    = reqTransDS.cursor();

    info(reqTrans.ItemId);

    sender.query().dataSourceName(sender.name()).addRange(fieldnum(ELCWDItemStockOverView,InventLocationId)).value("WAREHOUSENAME");
}
The query runs fine when I hard code the Warehouse name. However... I want to take the warehouse based on the selected Reqtrans record. Therefore I need the ReqTrans. 
To get it, I retrieve the formrun from th sender, and afterwards try to get the data usin .cursor(). However: the record is empty the first time the form loads.
 
 
 
 
 
 
When I click the refresh button, it gives the record:
 
 
 
It seems that the sequence of loading of the datasets is not in the right order or something. Is there something I can do to prevent this ?
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    304,293 Super User 2026 Season 1 on at
    Hi Willem,
     
    On the ReqTrans data source, you can write an extension for the active method and then call the executeQuery() method of your ELCWDItemStockOverView data source.
  • Willem van Duren Profile Picture
    230 on at
    Thanks André!
     
    I am one step further thanks to you.
     
    I have added the extension:
     
    [ExtensionOf(formDataSourceStr(ReqTransOverview, Reqtrans))]
    final class ELCWDReqtransOverviewForm_Extension
    {
        int active()
        {
            int ret = next active();
            
            FormRun formrun = this.formrun();
    
            FormDataSource  formDS = FormRun.dataSource(formDataSourceStr(ReqTransOverview,ELCWDItemStockOverview));
    
            formDS.executeQuery();
            return ret;
        }
    }
     
    This works. The data is now present from the beginning. However: when I open the inventory tab with the ELCWDItemStockOverView (my custom View) data displayed on a grid, the first time it shows the right data (the data of the first warehouse). When I click the second warehouse, it shows inventory of the first warehouse and the second warehouse. Then when I click the third one, the data of the first three is displayed. So it seems that the range is not replaced, but added.
  • Willem van Duren Profile Picture
    230 on at
    Solved it! It appears you need to remove the ranges when executing the query again.
     
    So my final ExecuteQuery override is:
     
    public class ELCWDReqTransOverviewForm
    {
        [FormDataSourceEventHandler(formDataSourceStr(ReqTransOverview, ELCWDItemStockOverView), FormDataSourceEventType::QueryExecuting)]
        public static void ELCWDItemStockOverView_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)
        {        
            FormRun formRun;
            FormDataSource  reqTransDS;
            ReqTrans reqTrans;
          
            reqTransDS  = sender.formRun().dataSource(formDataSourceStr(ReqTransOverview, ReqTrans));
    
            reqTrans    = reqTransDS.cursor();
    
            sender.query().dataSourceName(sender.name()).clearRanges();
            sender.query().dataSourceName(sender.name()).addRange(fieldnum(ELCWDItemStockOverView,InventLocationId)).value(reqTrans.inventDim().InventLocationId);
            sender.query().dataSourceName(sender.name()).addRange(fieldnum(ELCWDItemStockOverView,configid)).value(reqTrans.inventDim().configid);
            sender.query().dataSourceName(sender.name()).addRange(fieldnum(ELCWDItemStockOverView,inventColorId)).value(reqTrans.inventDim().inventColorId);
    
        }
    }
     
    Thanks again André!
  • André Arnaud de Calavon Profile Picture
    304,293 Super User 2026 Season 1 on at
    Hi Willem,

    Great to hear that you solved your issue. Can you mark a question to get the status of this question to Answered?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 688

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 524 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 301

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans