Skip to main content
X++ Development · · 1 min read

Get Expiry Date from Inventory Batch

Retrieve an inventory batch expiry date in D365 F&O using X++ for batch tracking and inventory-related processing.

Ahmad Hassan

Ahmad Hassan

Dynamics 365 F&O Consultant

Share
Get Expiry Date from Inventory Batch

This display method retrieves the expiry date associated with the selected inventory batch. It obtains the relevant InventDim record from the InventOnhandItem form and identifies the corresponding inventory information using the item and inventory dimension. The method then retrieves the batch expiry date from InventBatch and returns it.

X++ Code

display TransDate expiryDate(InventSum _inventSum )
    {
        InventBatch inventBatch;
        InventDim   inventDim =this.inventDim();
       // InventSum inventsum = this.cursor();
        InventDim                    inventDimLoc;
        InventSum                    inventSumLoc;

        FormObjectSet formObjectSet = this.formRun().dataSource(formDataSourceStr(InventOnhandItem, InventDim));
        FormDataSource inventDim_fds   = formObjectSet as FormDataSource;
        Common InventDimJoined         = formJoinedRecord(_inventSum, inventDim_fds);

        inventDimLoc = InventDimJoined as InventDim;

        select firstonly inventSumLoc
        where inventSumLoc.ItemId == _inventSum.ItemId
&& inventSumLoc.InventDimension1 == inventDimLoc.InventDimension1;



    
           select firstonly expDate from inventBatch
                where inventBatch.ItemId      == inventSumloc.ItemId
&& inventBatch.InventBatchId == inventDimLoc.InventBatchId;
        return inventBatch.expDate;

    
    }

Process Flow

The display method receives an InventSum record and obtains the related InventDim data from the InventOnhandItem form.

It uses formJoinedRecord() to identify the relevant inventory dimension and searches InventSum using the item and dimension information.

The method then finds the corresponding InventBatch using the item and batch ID.

Finally, it returns the expDate value from the selected inventory batch.

9e3f17ee-3fb1-4da2-b1f0-0aa06b889868.png

Figure: Flow of retrieving the expiry date for the selected inventory batch.

Found this useful?

Share it with your network

Ahmad Hassan

Written by

Ahmad Hassan

Microsoft Dynamics 365 & Power Platform blogger.

More about me

Related Posts

Comments

Leave a comment