Skip to main content

Notifications

Announcements

No record found.

Supply chain | Supply Chain Management, Commerce
Unanswered

How to add on-hand inventory quantity in Product Search View in Dynamics 365 Commerce?

Posted on by 24

pastedimage1679048665091v1.png

Here is my code CustomProductSearchColumns.ts file, but on-hand quantity is not showing. Can anybody guide me how to show item on-hand quantity on Product Search

import { IProductSearchColumn } from "PosApi/Extend/Views/SearchView";
import { InventoryLookupOperationRequest, InventoryLookupOperationResponse } from "PosApi/Consume/OrgUnits";
import { ICustomColumnsContext } from "PosApi/Extend/Views/CustomListColumns";
import { CurrencyFormatter } from "PosApi/Consume/Formatters";
import { ProxyEntities } from "PosApi/Entities";
//import { ProxyEntities } from "PosApi/ClientEntities";
import { ClientEntities} from "PosApi/Entities";

function getOnhand(context: ICustomColumnsContext, recordId: ProxyEntities.ProductSearchResult, search: ProxyEntities.OrgUnitAvailabilitySearchCriteria): Promise<number> {
return new Promise((resolve, reject) => {
let correlationId: string = context.logger.getNewCorrelationId();

let request: InventoryLookupOperationRequest<InventoryLookupOperationResponse> =
new InventoryLookupOperationRequest<InventoryLookupOperationResponse>(recordId.RecordId, correlationId, search);
console.log(`Request my debugger: ${request}`);
console.table([request]);
context.runtime.executeAsync(request)
.then((result: ClientEntities.ICancelableDataResult<InventoryLookupOperationResponse>) => {
if (!result.canceled) {
resolve(result.data.orgUnitAvailability[0].ItemAvailabilities[0].AvailableQuantity);
} else {
resolve(0);
}
})
.catch((error: any) => {
reject(error);
});
});
}


export default (context: ICustomColumnsContext): IProductSearchColumn[] => {


return [
{
title: "Item ID_CUSTOMIZED",
computeValue: (row: ProxyEntities.ProductSearchResult): string => { return row.ItemId; },
ratio: 20,
collapseOrder: 3,
minWidth: 120
}, {
title: "Name",
computeValue: (row: ProxyEntities.ProductSearchResult): string => { return row.Name; },
ratio: 40,
collapseOrder: 2,
minWidth: 150
}, {
title: "Onhand",
computeValue: (row: ProxyEntities.ProductSearchResult): string => {
let searchCriteria = new ProxyEntities.OrgUnitAvailabilitySearchCriteriaClass();
searchCriteria.OrgUnitNumber = "052";
searchCriteria.OrgUnitName = "HOUSTON"; // Set the name property
let onhand: Promise<number> = getOnhand(context, row, searchCriteria);
return onhand.toString();
},
ratio: 20,
collapseOrder: 4,
minWidth: 200
}, {
title: "Price",
computeValue: (row: ProxyEntities.ProductSearchResult): string => { return CurrencyFormatter.toCurrency(row.Price); },
ratio: 20,
collapseOrder: 1,
minWidth: 100,
isRightAligned: true
}
];
};

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans