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

Opening Form With Specific Record for Custom Table Is Showing Wrong Record

(0) ShareShare
ReportReport
Posted on by 2,346

HI All

The following code when executed is opening customer form for account number specified i.e. 0001

static void Job1(Args _args)
{
    MenuFunction menuFunction;
    CustTable bufferRecord;
    
    _args = new Args();
    
    bufferRecord = CustTable::find('0001');
    
    menuFunction = new MenuFunction(menuitemDisplayStr(CustTable), MenuItemType::Display);
    
    _args.record(bufferRecord);
    menuFunction.run();
}

but when the same code is executed for the custom table is opening first record in table instead of the record with recid 5637161829.

static void Job1(Args _args)
{
    MenuFunction menuFunction;
    MyCustomTable bufferRecord;
    
    _args = new Args();
    
    bufferRecord = MyCustomTable::findbyRecId(5637161829);
    
    menuFunction = new MenuFunction(menuitemDisplayStr(MyCustomTable), MenuItemType::Display);
    
    _args.record(bufferRecord);
    menuFunction.run();
}

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Your both jobs have the same bug: you don't pass the args when you call menuFunction.run().

    Please fix that and try again. The first job just happens to "work" since you perhaps selected the first CustTable record ("0001"), and the form shows the first record even without any args being passed.

    Second, did you debug your job to make sure that a bufferRecord was actually found with that rec id?

  • Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at

    Is MyCustomTable the first data source of the form? What about relations?

    Doesn't the form contain code that breaks the standard behaviour?

    By the way, please use Insert > Insert Code (in the rich-formatting view) to paste source code. It preserves indentation, which makes code much easier to read.

  • haroonattari Profile Picture
    2,346 on at

    @Nikolas, the record is passed in line # 12 in both jobs. Moreover, record with recid exists in MyCustomTable.

    @Martin, MyCustomTable is first data source on the form. I do not see any code that might be preventing the standard behavior. Although, there are other tables on the form but when I am opening that record from list page it is working fine.

  • Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at

    Do you get the right record in form's init()?

    How does the resulting form query look like?

  • haroonattari Profile Picture
    2,346 on at

    I added following infolog in form's init method and it is showing correct recid.

       info(strFmt("%1", element.args().record().RecId));

  • Verified answer
    Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at

    Then I would do the two things I already mentioned.

    Look at the query - you can see it in the Personalization form. What you'll do next depends on how what you find there.

    But you can also try another thing - if the table doesn't have a relation to itself (typically through a data type used for it's primary column), try adding it. To be honest, I don't remember if this is needed, but you can easily test this theory.

  • haroonattari Profile Picture
    2,346 on at

    Hi Martin

    Looking at Query tab revealed that there were two tables out of which one does not have any relation at all with MyCustomTable and there was no direct relation for other table on form. The relation for the later table was set on modified method of field using QueryBuildDataSource.

    As this form was developed by other developer and I do not want to mess up with his code, I applied the workaround mentioned in this blog and it is working fine.

    Thanks

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... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans