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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

How to get current active data source in d365 F&O form like standard docu view form

(4) ShareShare
ReportReport
Posted on by 97
ObjectIdent lastActivatedForm = infolog.parmLastActivatedForm();
if (lastActivatedForm)
{
    formRun = lastActivatedForm.object();
    if (formRun)
    {
        primaryTable = tableId2name(formRun.docCursor().TableId);
    }

 
this is the logic used in docu view form init() method to get the active data source name.
 
but when i use the same code in my logic i get only the default data source name as a table name.
 
 public void init()
 {
     ObjectIdent lastActivatedForm = infolog.parmLastActivatedForm();
     FormRun   formRun1 = lastActivatedForm.object();
     TableName table = tableId2name(formRun1.docCursor().TableId);
     super();
     this.design().controlName("SystemDefinedManageViewFilters").visible(false);
 } this is my code used in my form 
 
my requirement is to open the form with the active data source when i open the form by clicking the command button
 
this is my form code
 
 
this is standard docu view form code
 
is there anything i missed in my code
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at
    Can you tell us more about the overall business scenario, please?
     
    Do I understand correctly that your actual question is why docCursor() method returns a SalesTable record in the the first case and a SalesLine record in the other case? Well, the scenarios don't seem to be identical. Unfortunately, you described none of them, therefore there isn't anything more I can say about them. We don't even know whether you're talking about the same form (in formRun/formRun1 variables). More information from you is desperately needed.
      
    Are you sure that you must use infolog.parmLastActivatedForm()? If you want to get a reference to the caller form, you can simply use this.args().caller().
     
    By the way, please use Insert Code Snippet button to insert code. You'll get this result:
    ObjectIdent lastActivatedForm = infolog.parmLastActivatedForm();
    if (lastActivatedForm)
    {
        formRun = lastActivatedForm.object();
        if (formRun)
        {
            primaryTable = tableId2name(formRun.docCursor().TableId);
        }
    } 
    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum, because it's about F&O and not about D365 in general.
  • CU28111010-1 Profile Picture
    97 on at
    thank's for the immediate reply @Martin Dráb,
     
    i'm trying to recreate the button like system defined attachment button to avail for all forms,i have attached the standard code and my code, 
     
     
    while opening the form through the button i need to get the last form's last active datasource record, in standard docuview it was working perfectly , i also used the same code but i was only getting the default datasource
  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at
     
    This doesn't really address the problem. You seem to be saying in your scenario (which is still unknown to us), you believe that docCursor() should return a record from SalesLine data source instead of the SalesTable data source. Is it so?
     
    Neverless let's make a step back an look at the business requirement. It seems that the actual problem you're trying to solve is "to avail for all forms". First of all, are you aware of the setup in Organization administration > Document management > Active document tables?
  • CU28111010-1 Profile Picture
    97 on at
    hello @Martin Dráb, below is my requirement in simple words,
     
    i simply need to get the currently active data source of the form which have multiple data source to pass the active datasource cursor record to my form is there any method to get the active form control?
  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at
    That's not a business requirement. That's a little implementation detail of a particular technical design that you've decided to use. But maybe the whole approach is wrong.
     
    Let's do it properly. Let's look at the business requirement to see if any change is needed (maybe you just need to add some tables to Active document tables) and if so, what needs to change. For example, maybe you just need to adjust some conditions in the standard logic and the whole idea of developing a new form is wrong.
  • Navneeth Nagrajan Profile Picture
    2,438 Super User 2025 Season 2 on at
    Hi Cu07020542-00,
     
    As Martin rightly mentioned, it is a strange business requirement. This requirement can be addressed through standard D365 FO (considering the screen clip that you shared is a Sales Order screen).

     
    Anyways, if it is a custom link that you are creating then you can follow the approach mentioned below.
    1. On the clicked event you can add the following snippet to retrieve the calling data source.
     
    Other Alternatives:
    Alternative Number 1:
    1. You can alternatively extend the doResearch() method from DocuView and there is a sample snippet available under DocuView_PersonnelManagement_Extension.

     
    Alternative Number 2:
    1. You can leverage the below mentioned standard method available under DocuView form.
     
    Alternative Number 3:
    Alternatively, you can also consider the following:
    1. Add a relation to the DocuRef table in the SalesTable. 
        SalesTable.DataAreaId == DocuRef.RefCompanyId
        SalesTable.TableId == DocuRef.TableId
        SalesTable.RecId == DocuRef.SalesRefRecId
     
    2. Next, you can add the following code to the OnInitialized method of DocuView.
     
    Hope this helps. Happy to answer questions, if any.
     
  • CU28111010-1 Profile Picture
    97 on at
    Thanks everyone for your replies and help! I appreciate the time and support.
  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at
    @CU07020542-0 What exactly was the solution? The reply you've marked as the verified answer suggests several different things, and to me, none of them seem to be addressing the problem. For example, the first suggestion assumes that you know the name of the data source and you can put the name into code, therefore it won't work for other data sources.
  • Verified answer
    CU28111010-1 Profile Picture
    97 on at
     
    yes, you are right the suggestion assumes that you know the name of the data source and you can put the name into code, therefore it won't work for other data sources.
     
    while i am debugging the standard document attacthment process i found the below method that used to show the attachment count of the cursered record 
     
    [SubscribesTo(classstr(info), delegatestr(info, docu_reSearch))]
    static void docu_reSearchSubscriber(FormRun formRun)
    {
             
    }
     
    so i just Subscribed this method and store the current record in my common table buffer and send the buffer as arg to the form 
     
    the below is my custom code to achieve my scenario 
     
    [SubscribesTo(classstr(info), delegatestr(info, docu_reSearch))]
    static void docu_reSearchSubscriber(FormRun formRun)
    {
        if(formRun.selectedControl() != null)
        {
              commontable = formRun.docCursor();              
        }        
    }
     
    commontable is buffer i globally assign
     
    and also doccursor retrun the datasource current record of the selected form control in my senario when i click my custom button the selectedcontrol is changed to my custom button which is not have datasource so the doccursor return the default datasource cursor redord 
     
    so change the code like this
     
    if(!(curcontrol as FormCommandButtonControl))
    {
        commontable = formRun.docCursor();
    }
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans