Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Better understand this logic.

(0) ShareShare
ReportReport
Posted on by 529

So I am not fimilar to creating queries in D365. I am trying to add a field to the load lines form(WHLoadTable). When I add the purchline datasource with an inner join to the whsloadline it goes from the query:  Query  object 4daf4050: SELECT FIRSTFAST FORUPDATE * FROM WHSLoadTable(WHSLoadTable) USING INDEX LoadIdIdx WHERE (((((WHSLoadTable.LoadDirection == 2) && (WHSLoadTable.LoadStatus != 6)) || ((WHSLoadTable.LoadDirection == 1) && (WHSLoadTable.LoadStatus != 8)))))     to just a simple select * from WHSLoadTable.

All the logic is in the init, but how does it get the query?  And where does the whsLoadTable_q variable come from? I can't find that anywhere?  Is that just a reference to the actual table?

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Better understand this logic.

    Try to get the FormDataSource in the variable and use it in the code.

    FormDataSource fds = element.FormDataSourceName_ds;
    qbrLoad = SysQuery::findOrCreateRange(fds.queryBuildDataSource(), fieldNUm(TableName, FieldName));

    Thanks,

    Girish S.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Better understand this logic.

    Try prefixing element keyword. element.DataSourceName_ds.

    Thanks,

    Girish S.

  • KeithM Profile Picture
    KeithM 529 on at
    RE: Better understand this logic.

    That helped. I also had the class name wrong and adjusted that. For some reason it can't find the reference for the _ds now. Do I need to declare that?  It wasn't declared in the original class anywhere, just assumed since it's a system variable.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Better understand this logic.

    Seems you have added COC for executeQuery method. In that case you need to write next statement. There wont be any super keyword in COC - You need to use next keyword like below.

    [ExtensionOf(formDatasourcestr(WHSLoadPlanningListPage, WHSLoadTable))]
    final class WHSLoadTable_Extension
    {
        public void executeQuery()
        {
            //add logic here.
            next executeQuery();
        }
    }

    Thanks,

    Girish S.

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,187 Super User 2025 Season 1 on at
    RE: Better understand this logic.

    HI Keith,

    What errors do you get now?

  • KeithM Profile Picture
    KeithM 529 on at
    RE: Better understand this logic.

    So digging through D365 documentation it looks like I need to create an extension of the datasource from the Form.

    So I have attempted to create that but get some errors that I am unsure of. I am trying to adjust the executequery method.

    [ExtensionOf(formDatasourcestr(WHSLoadPlanningListPage, WHSLoadTable))]
    final class WHSLoadTable_Extension
    {
        public void executeQuery()
        {
            if (!filteredByMenuItem)
            {
                qbrLoad = SysQuery::findOrCreateRange(WHSLoadTable_ds.queryBuildDataSource(), fieldNum(WHSLoadTable, LoadStatus));
                    
                if (showClosedLoads)
                {
                    qbrLoad.value('');
                }
                else
                {
                    str loadStatusFilterStr = strFmt('(((%1.%2 == %4) && (%1.%3 != %5)) || ((%1.%2 == %6) && (%1.%3 != %7)))',
                                                            formDataSourceStr(WHSLoadPlanningListPage, WHSLoadTable),   // 1
                    fieldStr(WHSLoadTable, LoadDirection),                      // 2
                    fieldStr(WHSLoadTable, LoadStatus),                         // 3
                    any2Int(WHSLoadDirection::Outbound),                        // 4
                    any2Int(WHSLoadStatus::Shipped),                            // 5
                    any2Int(WHSLoadDirection::Inbound),                         // 6
                    any2Int(WHSLoadStatus::Received));                          // 7
    
                    qbrLoad.value(loadStatusFilterStr);
                }
            }
    
            super();
        }
    }

  • KeithM Profile Picture
    KeithM 529 on at
    RE: Better understand this logic.

    When I was debugging and understanding the code I put a break at this point(below). Rolled over the qdps(QueryBuilddatasource) and it gave me that select, which is the same select if you select the form information in D365. I'm just not sure where that is being built at.  The query for this is empty.

    qbds = whsLoadTable_q.dataSourceTable(tableNum(WHSLoadTable));

    pastedimage1686149563604v1.png

    Query:

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Better understand this logic.

    Where did you get this query statement?

    Thanks,

    Girish S.

  • KeithM Profile Picture
    KeithM 529 on at
    RE: Better understand this logic.

    Thank you... I figured it had to be some type of system variable since I couldn't find the reference anywhere. Now how is it when I debug, the query is being build with a statement of ( SELECT * FROM WHSLoadTable(WHSLoadTable) USING INDEX LoadIdIdx WHERE (((((WHSLoadTable.LoadDirection == 2) && (WHSLoadTable.LoadStatus != 6)) || ((WHSLoadTable.LoadDirection == 1) && (WHSLoadTable.LoadStatus != 8))))) )? 

    I don't see this being built anywhere. I looked to see if there was a query which there was but it's blank.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Better understand this logic.

    Hi Keith,

    When you type in DataSourceName_ - This will show all the available member variables.

    As Andre mentioned DataSourceName_ds, DataSourceName_q,DataSourceName_qr - This are all member variables for the datasource.

    DataSourceName_q will return the query output for the DataSource and DataSourceName_qr will return the query run for the DataSource.

    Thanks,

    Girish S.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,187 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,966 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans