Thank you SO MUCH for this information Juliet.
I was able to use it in my CRT trigger and I finally have the same quantities that is shown in inventory lookup view. I tried for the longest time to get the same quantities with a SQL view script but there was always an issue somewhere with some product that it just doesn't gave the same quantities.
For those that need to also add custom columns to show the same quantities that is on Inventory lookup, like I had to do for the product search view, here is what I did.
*****
I added a public class in my CRT project and extended it from IRequestTrigger:
GetProductSearchTriggers : IRequestTrigger
I added support request type: GetProductSearchResultsDataRequest, because I had to do it for the product search view.
For the onExecuted method I looped through the products returned by the GetProductSearchResultsDataResponse and called the trigger Juliet gave me. It doesn't have a response , so I used the generic EntityDataServiceResponse but for entity OrgUnitAvailability.
I added extension properties to each product specific for the 3 quantities, but I assume one can add the OrgUnitAvailability as an extension property and then on the POS side pulls out the values.
public void OnExecuted(Request request, Response response)
{
var productsList = ((EntityDataServiceResponse<ProductSearchResult>)response);
foreach (ProductSearchResult product in productsList)
{
OrgUnitAvailabilitySearchCriteria srchCriteria = new OrgUnitAvailabilitySearchCriteria();
srchCriteria.OrgUnitName = request.RequestContext.GetOrgUnit().OrgUnitName;
srchCriteria.OrgUnitNumber = request.RequestContext.GetOrgUnit().OrgUnitNumber;
SearchOrgUnitAvailabilitiesServiceRequest availRequest = new SearchOrgUnitAvailabilitiesServiceRequest(
product.RecordId, srchCriteria, QueryResultSettings.AllRecords);
EntityDataServiceResponse<OrgUnitAvailability> availResponse =
request.RequestContext.Execute<EntityDataServiceResponse<OrgUnitAvailability>>((Request)availRequest);
PagedResult<OrgUnitAvailability> extensions = availResponse.PagedEntityCollection;
IEnumerable<ItemAvailability> fList = new List<ItemAvailability>();
foreach (OrgUnitAvailability obj in extensions)
{
fList = obj.ItemAvailabilities;
foreach(ItemAvailability vI in fList)
{
iQty += vI.AvailableQuantity;
rQty += vI.PhysicalReserved;
oQty += vI.OrderedSum;
}
}
CommerceProperty availPhys = new CommerceProperty();
availPhys.Key = "Inventory";
availPhys.Value = iQty.ToString("0.####");
product.ExtensionProperties.Add(availPhys);
CommerceProperty reserveQty = new CommerceProperty();
reserveQty.Key = "Reserved";
reserveQty.Value = rQty.ToString("0.####"); ;
product.ExtensionProperties.Add(reserveQty);
CommerceProperty orderQty = new CommerceProperty();
orderQty.Key = "Ordered";
orderQty.Value = oQty.ToString("0.####"); ;
product.ExtensionProperties.Add(orderQty);
}
}
*****