Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

Multiple form datasrouces

Posted on by 55
Hi.
 
I have a form (Details Transaction pattern) with 2 datasources. Form allows end user to see records on the grid and open a particular record in Detailed Tab to view/update it.
Main datasource is a table where records are saved and second one is a view, which I use to display data related to the main table (I didn't want to create many duplicate fields on the main table when data is stored in another table already). When I create a record my second datasource (which is a view and brings related data so end user can see it) isn't refreshed. Unless I click refresh button and/or reload the page, second datasrouce data isn't there. As well, I noticed that after creating several records and if I'm to add another new record and click refresh button the grid position isn't kept and first record is loaded on the form.
 
Any thoughts what am I doing wrong or not doing here? If more info is needed please ask. 
 
Thank you,
Alex
  • Alex Nach Profile Picture
    Alex Nach 55 on at
    Multiple form datasrouces
    Thank you Andre. I really appreciate this. Alex.
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 288,459 Super User on at
    Multiple form datasrouces
    Hi Alex,
     
    Thanks for the clarification. Retrieving a read-only record from a view upon data entry is not common. I think you have a viable workaround to refresh the view when modifying the DeductionId. 
  • Alex Nach Profile Picture
    Alex Nach 55 on at
    Multiple form datasrouces
    Hi Andre,
    I'm displaying about 12 read-only fields from the view. I understand that data won't be pulled before the save happens, but the issue is that the data doesn't appear even after the save is performed. DeductionId is a mandatory field on the form (lookup), so it gets validated before the form is saved. I thought saving the form would refresh the datasource and populate the data from the view, but that's not the case.
    I experimented with different events on the form and my table, particularly with the validateWrite event, trying to refresh the form datasource, but nothing worked 100% in terms of refresh, record position, etc. Eventually, I stumbled upon the Form Control Event Handler for the DeductionId control and refreshed the datasource from there. This did the job, but it feels like an overly complicated solution, and there should be a simpler way to achieve this.
     
    public static void Table_DeductionID_OnModified(FormControl sender, FormControlEventArgs e)
        {
            ;
            FormDataSource formDs = sender.formRun().dataSource(); 
            formDs.research();
        }
     
    Thank you, Alex
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 288,459 Super User on at
    Multiple form datasrouces
    Hi Alex,
     
    Thanks for the additional details. In case someone creates a new record, the record is initially not saved and can't present data from the related view. How many fields do you need to display?
  • Alex Nach Profile Picture
    Alex Nach 55 on at
    Multiple form datasrouces
    Hi Andre/Anton,
     
    Just to clarify. I do not need to update anything on the second datasrouce it's only there for references. My first datasrouce allows end user to select deduction Id and I decided to create a view of a deduction table as half of the data is stored there already but user needs to see it when filling up the desired form. I set create/delete/edit on the view datasrouce to No. Originally I added deduction table in there and set all behaviors to No and access right to View only but D365 was complaining every time I would try to save a record with the deduction id being required (not sure why since I linked it and it exists).
     
    Here is the relation between 2 datasources. 
    Datasrouce for table

     
    Datasrouce for view
     
    and code behind
    public void init()
            {
                super();
                QueryBuildDataSource qbds;
                qbds = this.queryBuildDataSource();
                qbds.clearLinks();
                qbds.addLink(fieldNum(View, TAMDeductionID), fieldNum(Table, TAMDeductionId));
            }
     
    Thank you, Alex
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 288,459 Super User on at
    Multiple form datasrouces
    Hi Alex,
     
    What exact form data source properties have you set for the view? What is the exact relation between your table and view?  
  • Anton Venter Profile Picture
    Anton Venter 9,930 Super User on at
    Multiple form datasrouces
    Hello,
     
    I guess that because the second datasource is a view, the refresh is not triggered because the data of a view is static and will not be updated. Why not change the design a bit? Use a single datasource and then have a split view with a grid on the left and the editable fields on the right?
     
    Can you explain why you chose this design?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans