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 :
Microsoft Dynamics AX (Archived)

findRecord not properly executed after jumping from forms

(0) ShareShare
ReportReport
Posted on by

Hi experts,

Currently, I have a problem with dealing with the findRecord method.

This is the scenario:

1) I have two forms and two tables. Lets name it form A (with table A) & form B (with table B)

2) form A has a behavior where a record will be left as a history in form B when user makes any changes to the record.

3) form B, which has many histories of form A, is linked with a table relation of foreign key (between table A & B).

4) I overrode the the jumpRef method in form B's datasource, so that I could link it back to form A (I coded with jumpRef because of some other complexities)

5) form A receives the args from form B, and executes findRecord method, so that within the many records, the user could see where the selected record is.

6) Problem: Test message runs fine, with record being printed out as info. However, grid in form A is not being selected (even with the findRecord method used)

Note: *I thought I used findRecord wrongly. So I created a test button to execute the method below upon clicked, and it worked (this happened in form A, after jumpRef-ing from form B to A when form A has fully loaded, then only did I click the test button, which worked)* 

Could anyone please kindly guide me or tell me what am I doing wrong?

Thanks in advance!

This is the script (the script below is being executed inside the datasource's init method; element.initHeader(record);, which has been overridden by me):

private str initHeader()
    {           
        info(funcName() + " has been executed");
        TableA  tableA;
        str                 strRegId;

        //if there is a caller form
        if (element.args().caller())
        {        
            switch(element.args().record().TableId)
            {
                case tableNum(TableA): 
                    info("TableA has been detected"); //prints out fine
                    tableA = element.args().record(); 

                    //Find and select the specified TranId
                    info(strFmt("TranId %1 has been found. It will now be selected in the grid.", tableA.TranId)); //prints out fine
                    HISSMARepairObject_ds.findRecord(localHISSMARepairObject);//not working
                    
                    //Assigning RefId to strRegId
                    strRegId = tableA.HISRegId;
                    break;
                default:
                    info("Table not recognized.");
                    break;
            }
        }
        
        return strRegId;
    }

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Bumped.

    Would gladly appreciate for any help at all...

    EDIT: I realized something strange during a debug using breakpoints in VS (visual studio)...findRecord returned a value of false even when I pass the element.args.record() to it directly... However, when I execute the test click button, findRecord returned a value of true, which then proceeds to passing the record to findRecord in the debugging window...

    Question: Is the datasource not fully loaded yet, when I try to call the findRecord method inside the datasource's init method?

  • Community Member Profile Picture
    on at

    Thank you so much for the reply Suktrut Parab!

    It is not working when I try to go to form B, from form A, to see the parent record on form A.

    This is the flow:

    Form B -> I click on one of the record, which has a value of "Test00001" -> pass caller, pass record -> executes form A -> form A gets loaded -> form A tries to findRecord with the passed record as the args -> findRecord returned a value of false

     

    However, after adding a test button in form A

    Form B -> I click on one of the record, which has a value of "Test00001" -> pass caller, pass record -> executes form A -> form A gets loaded -> form A datasource's init method executes initHeader() method, which I mentioned at the top -> form A tries to findRecord with the passed record as the args -> findRecord returned a value of false -> I click the test button -> test button executes initHeader() method, again -> findRecord returned a value of true, and it worked

     

    Also, this is the code which I gave to jumpRef in form B, by overriding it:

    public void jumpRef()
            {
                //super();
    
                TableB       tableB = tableB;
                TableA       tableA;
                Args                    args = new Args();
                MenuFunction            menuFunction;            
    
                //info(strFmt("tableB TranId is currently: %1",tableB.TranId));
    
                if(tableA.checkExist(tableB.TranId))
                {
                    args.caller(element);
                    args.record(tableA::find(tableB.TranId));         
                    menuFunction = new MenuFunction(menuItemDisplayStr(formADetailPage),MenuItemType::Display);
                }            
                else
                {
                    error("An error has appeared. The same record could not be found in tableA");
                }
    
                menuFunction.run(args);
                menuFunction.wait();
            }


  • Community Member Profile Picture
    on at

    Hi Sukrut, thanks for the prompt reply again.

    I tried overriding the run method in form A and directly use "formDatasource_ds.findRecord(element.args().record())" (after jumping from formB to formA), but the debug still says a value of "false". At this stage, I really think it's impossible to use the findRecord, not only unless the form is fully loaded, where the user then interacts with the form using some sort of button...

    PS: I've looked through that URL which you gave, and looking through what I coded and the code which I posted above, I think it is identical...Is there any problem/potential error within my jumpRef code?

    Thanks in advance!

  • Community Member Profile Picture
    on at

    I wrote it by overriding the jumpRef method in datasource tableB in formB, which then allows me to jump to form A.

    Also, I just tried hard coding without passing any args in form A, with the code below and it did not work...

    public void run()
        {
            super();
    
            TableA tableA;
    
            select tableA
                where tableA.TranId == "TRAN-000000002";
    
            //Find and select the specified TranId
            info(strFmt("TranId %1 has been found. It will now be selected in the grid.", tableA.TranId)); //this message runs fine
            TableA_ds.findRecord(tableA); //returns a value of false in VS debug message
        }

    PS: I did exactly like you said with jumpRef...and it is still not working...Everything only works when the form is fully loaded, and only when the user interacts with the form with a button...

    Does findRecord not work at all when a user jumps from a form to another? If that is the case, how do I get a particular record to be selected/ highlighted (not marked)?

  • Verified answer
    Community Member Profile Picture
    on at

    Thanks for the reply again Sukrut.

    However, I think I found a solution to it, which is not as simple as I thought it would be.

    Please refer to https://community.dynamics.com/ax/f/33/t/149154 thread for those who are having trouble like me. Also, refer to this URL too https://stackoverflow.com/questions/5596930/dynamics-ax-2009-go-to-main-table-form-how-to-select-the-default-row.

    The solution is to use lookupRecord instead of findRecord. findRecord was called too early in my case, which is actually called during the datasource's executeQuery. However, for my case, I did lots of digging, and found out that lookupRecord does not work with any datasources that has a "join" to the main parent datasource. AX will complain that it cannot find the root datasource table in the form (Exact error message would be "Could not process the lookupRecord value on the Args instance. The table 'blah blah' does not exist as a root FormDataSource for the form 'blah blah FormName'."), even though we have it inside our form.  I will try to find an alternative version to it.

    Thanks again for all the help Sukrut.

    EDIT: For those who are like me, who could not use lookupRecord (due to multiple datasources joining with each others), you could still use findRecord to achieve this. The thing is that you have to place it inside the datasource's executeQuery method (by overriding the method) in order for it to work.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans