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

Announcements

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
    306,230 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
    306,230 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Subra Profile Picture

Subra 409

#3
Martin Dráb Profile Picture

Martin Dráb 280 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans