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

Community site session details

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

CoC on form ExecuteQuery issue

(0) ShareShare
ReportReport
Posted on by

Hello guys,

I'm creating a CoC on FormDataSource for my form LedgerJournalTable, it was supposed to filter the list on the grid based on the menu item calling the form. While it is works, I found from the original menu the grid list became "broken". As the LedgerJournalTable form is a General Journal, I found out, the filter no longer works means all journal not only Daily journal (journal type) listed there, also the option to filter Not Posted and Posted no longer works.

I created the CoC to be like this : 

[ExtensionOf(FormDatasourceStr(LedgerJournalTable, LedgerJournalTable))]
final class ABC_FormLedgerJournalTable_Extension
{
    public void ExecuteQuery()
    {
        
        if (this.formRun().args().menuItemName() == menuitemdisplaystr(ABC_Payments))
        {
            //get caller record
            ABC_Table   ABCTable = this.formRun().args().record();
            ABC_Line    ABCLine
            
            QueryBuildDataSource        qbdsLedgerJournalTrans;

            
            //strInvoice = subStr(strInvoice,1, strLen(strLTrim(strRTrim(strInvoice)))-1);
            //adding filter to datasource
            qbdsLedgerJournalTrans = this.queryBuildDataSource().addDataSource(tableNum(LedgerJournalTrans));
            qbdsLedgerJournalTrans.joinMode(JoinMode::ExistsJoin);
            qbdsLedgerJournalTrans.relations(true);
            
            while select ABCLine where ABCLine.DocNumber == ABCTable.DocNumber
            {
                qbdsLedgerJournalTrans.addRange(fieldnum(LedgerJournalTrans, MarkedInvoice)).value(queryvalue(ABCLine.InvoiceId));
            }
                        
        }
        next executeQuery();

    }

}

What should I do here ? should I added else condition ? but to me seems odd since if the menu item is not what I specified (my custom menu item), the query will not even altered right ?

Please advice,

Thanks

I have the same question (0)
  • VoltesDev Profile Picture
    on at
    RE: CoC on form ExecuteQuery issue

    Hi Martin,

    The "original menu" I mean is General Journal > Journal. What I'm trying to do with my CoC is to handle when this form called from other menu item.

    And the CoC, as you mentioned also, although it is adding extra datasource, it will only used (added) if calling by that menu item specified, right ? I did debug this also, and if it calling from General Journal (original menu), it will not go in my "addDataSource", will go directly to "next ExecuteQuery".

    Anyway it looks like the problem does because of my CoC, since if I deleted this class, the problem gone.

    If I check the query (from the UI -> form information), when there is no CoC (deleted), the original query will start like this :

    SELECT FIRSTFAST FORUPDATE * FROM LedgerJournalTable(LedgerJournalTable) USING INDEX TypeNumIdx WHERE ((Posted = 1)) AND ((UserBlockId = '' OR UserBlockId = N'username')) AND ((GroupBlockId = '' OR GroupBlockId = '')) AND ((JournalType = 0)) OUTER JOIN FORUPDATE * FROM LedgerJournalTable_W........

    But if my CoC exists, the "where" clause is missing :

    SELECT FIRSTFAST FORUPDATE * FROM LedgerJournalTable(LedgerJournalTable) USING INDEX TypeNumIdx OUTER JOIN FORUPDATE * FROM LedgerJournalTable_W.......

    Thanks

  • Martin Dráb Profile Picture
    236,184 Most Valuable Professional on at
    RE: CoC on form ExecuteQuery issue

    Your code adds adds an extra data source and range every time the query executes, e.g. when user sorts the grid. That's an obvious bug. I believe you should move your code from executeQuery() to init().

    When you say "I found from the original menu", do you mean calling LedgerJournalTable form from a different menu item than ABC_Payments? If so, the code above isn't used in that case and therefore the problem is caused by something else. You can debug code to find where things go wrong.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,339

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 600 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans