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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Vendor batch number in on hand form

(4) ShareShare
ReportReport
Posted on by 636
Hi Experts,
 
I need to add the vendor batch number to the On-hand form in D365. I was able to add it using the code below, and it worked correctly for the first item I tested. However, after changing the display dimensions, I began receiving the error shown below. Could you please help me identify what went wrong?
 
 
[ExtensionOf(classStr(InventDimCtrl_Frm_OnHand))]
final class InventDimCtrl_Frm_OnHand_Extension
{   
    public void modifyQueryBasedOnDatasourceName(
        Query          _inventSum_DS_Query,
        str            _inventSum_DS_Name,
        FormDataSource _inventDim_DS)
    {
    
        next modifyQueryBasedOnDatasourceName(_inventSum_DS_Query,
                                                _inventSum_DS_Name,
                                                _inventDim_DS);
        InventDimParm inventDimParmGroupBy = InventDimParm::orParmsAll(dimParmLockedRightClick, dimParmVisibleGrid);
        if (inventDimParmGroupBy.InventBatchIdFlag)
        {
            if (!_inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)))
            {
                _inventSum_DS_Query.dataSourceTable(tableNum(InventDim)).addDataSource(tableNum(InventBatch), 'PBFInventBatch');
            }
            
            _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).relations(false);
            _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).joinMode(JoinMode::OuterJoin);
            _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).clearLinks();
            _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addLink(fieldNum(InventDim, inventBatchId), fieldNum(InventBatch, inventBatchId));
            _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addLink(fieldNum(InventSum, ItemId), fieldNum(InventBatch, itemId), tableStr(InventSum));
            _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addGroupByField(fieldNum(InventBatch, PdsVendBatchId));
        }
    }
}
 
 
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at
    Please share the errors. Your screenshot shows just the beginning of two of five error messages.
     
    By the way, I see you add the data source if InventBatchIdFlag is enabled, but you don't disable the data source if InventBatchIdFlag becomes inactive.
  • D365  beginner Profile Picture
    636 on at
    Hi Mr. Martin, 
     
    Below are the errors. 

    1. session 2066111 ()
    2. SELECT SUM(T1.POSTEDQTY),SUM(T1.POSTEDVALUE),SUM(T1.PHYSICALVALUE),SUM(T1.DEDUCTED),SUM(T1.REGISTERED),SUM(T1.RECEIVED),SUM(T1.PICKED),SUM(T1.RESERVPHYSICAL),SUM(T1.RESERVORDERED),SUM(T1.ONORDER),SUM(T1.ORDERED),SUM(T1.ARRIVED),SUM(T1.QUOTATIONRECEIPT),SUM(T1.QUOTATIONISSUE),SUM(T1.PHYSICALINVENT),SUM(T1.AVAILPHYSICAL),SUM(T1.AVAILORDERED),T1.ITEMID,T2.INVENTBATCHID,T3.NAMEALIAS,T4.PDSVENDBATCHID FROM INVENTSUM T1 CROSS JOIN INVENTDIM T2 CROSS JOIN INVENTTABLE T3 LEFT OUTER JOIN INVENTBATCH T4 ON (((T4.PARTITION=5637144576) AND (T4.DATAAREAID=N'sapu')) AND (T1.AVAILORDERED=T4.INVENTBATCHID)) WHERE (((T1.PARTITION=5637144576) AND (T1.DATAAREAID=N'sapu')) AND ((T1.CLOSED=?) AND (T1.ITEMID LIKE ? ESCAPE '\' ))) AND (((T2.PARTITION=5637144576) AND (T2.DATAAREAID=N'sapu')) AND (T1.INVENTDIMID=T2.INVENTDIMID)) AND (((T3.PARTITION=5637144576) AND (T3.DATAAREAID=N'sapu')) AND (T1.ITEMID=T3.ITEMID)) GROUP BY T1.ITEMID,T2.INVENTBATCHID,T3.NAMEALIAS,T4.PDSVENDBATCHID ORDER BY T1.ITEMID,T2.INVENTBATCHID,T3.NAMEALIAS,T4.PDSVENDBATCHID OPTION(FAST 21)
    1. 3. [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Error converting data type nvarchar to numeric.
    2. 4. Object Server Azure:
    5. Cannot select a record in On-hand inventory (InventSum). The SQL database has issued an error.
     
  • Navneeth Nagrajan Profile Picture
    2,538 Super User 2026 Season 1 on at
    Hi,
     
     A few Suggestions:
     
    1. Assuming you are looking to add the PdsVendBatchId on the InventOnhandItem form. Looks like on changing the display dimensions the InventDim is appearing blank and so is InventbatchId. As Martin rightly said, you need to add a validation like this. IF the batch id is blank your code could break.
     
    else if (!inventDimParmGroupBy.InventBatchIdFlag)
    {
    //some code 
    _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).relations(false);
                _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).joinMode(JoinMode::OuterJoin);
                _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).clearLinks();
                _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addLink(fieldNum(InventDim, inventBatchId), fieldNum(InventBatch, inventBatchId));
                _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addLink(fieldNum(InventSum, ItemId), fieldNum(InventBatch, itemId), tableStr(InventSum));
                _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)).addGroupByField(fieldNum(InventBatch, PdsVendBatchId));
     
            //Make the vendor batch field available in the query result
            _inventSum_DS_Query.addSelectoinField(fieldNum(InventBatch, PdsVendBatchId), SelectionField::QueryValue);
    }
     
    2. An alternative to the above suggestion. You can also use the InventOnhandItem and write a COC like this. Tried the below suggestion and it worked (in case if the requirement is to add the PdsVendBatchId to the On Hand screen).
     
    [ExtensionOf(formDataSourceStr(InventOnhandItem, InventSumDeltaDim))]
    final class InventSumDeltaDim_InventOnhandItem_DS_Extension
    {
        public void init()
        {
            next init();
     
            QueryBuildDataSource qbdsInventSum = this.queryBuildDataSource();
            QueryBuildDataSource qbdsInventDim;
            QueryBuildDataSource qbdsInventBatch;
            // Existing join to InventDim (usually already there)
            qbdsInventDim = qbdsInventSum.addDataSource(tableNum(InventDim));
            qbdsInventDim.joinMode(JoinMode::ExistsJoin);
            qbdsInventDim.addLink(fieldNum(InventSumDeltaDim, InventDimId),
                                  fieldNum(InventDim, InventDimId));
           
            // Join InventBatch via InventDim.InventBatchId
            qbdsInventBatch = qbdsInventDim.addDataSource(tableNum(InventBatch));
            qbdsInventBatch.joinMode(JoinMode::OuterJoin); // Assumption - Outer because not every item has batch
            qbdsInventBatch.relations(true);
            qbdsInventBatch.addLink(fieldNum(InventDim, InventBatchId),
                                   fieldNum(InventBatch,InventBatchId));
     
            // Select the vendor batch field so it can be displayed
            qbdsInventBatch.addSelectionField(fieldNum(InventBatch, PdsVendBatchId), SelectionField::QueryValue);
        }
    }
     
    In addition to this, set the Autodeclaration property to Yes for the field after this field is added to the form extension.
    [ExtensionOf(formStr(InventOnhandItem))]
    final class InventOnhandItem_Form_Extension
    {
        public void init()
        {
            next init();

            this.design().controlName(formControlStr(InventOnhandItem, InventBatch_PdsVendBatchId)).visible(true);
        }
    }
     
    Hope this helps. Happy to answer questions, if any.
  • Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at
    The problem is in the comparison T1.AVAILORDERED=T4.INVENTBATCHID, where you're comparing fields of incompatible data types. According to your code, you actually wanted to use T2.InventBatchId instead of T1.AvailOrdered. It's not clear to me why, but it seems that the parent of the data source returned by _inventSum_DS_Query.dataSourceTable(tableNum(InventBatch)) is InventSum and not InventDim. Please check how the query looks like at runtime.
  • D365  beginner Profile Picture
    636 on at
    Thank you, Navneeth, for your suggestions. When I reviewed the code you mentioned, which is working, I noticed that there is no datasource named InventSumDeltaDim in the InventOnhandItem form. 
  • D365  beginner Profile Picture
    636 on at
    Any assistance on this would be greatly appreciated.
  • Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at
    Have you looked at what I mentioned above?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans