I have custom on the IRequestTrigger for supported request type: GetProductSearchResultsDataRequest.
OnExecuted, it will loop through all the products returned by the response and then for each product retrieve the inventory and populate the extension properties so that I can list in product search grid in POS the inventory for each product. This works 100% in CPOS/MPOS.
We are now going to use eCommerce as well. The latter refuse to show the products. We contacted Microsoft and they came back with the following error:
***
An error occurred during the Retail Server Request. Exception: System.NullReferenceException: Object reference not set to an instance of an object. at TMCProductSearchViewCRT.GetProductSearchTriggers.OnExecuted(Request request, Response response) at Microsoft.Dynamics.Commerce.Runtime.RequestTriggerAsyncAdapter.OnExecuted(Request request, Response response) at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.d__40.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
***
I then commented out my custom and the products showed up in eCommerce. I then started to uncomment pieces of the custom code until I can pinpoint the custom that is causing the error. When I uncommented just the skeleton of the OnExecuted, eCommerce still showed the products. I can also uncomment the loop through the products and assign zeroes to the extension properties and it will still be okay. But the moment it has to call the standard request/response pair to retrieve the inventory from the channel DB, it failed.
Apparently eCommerce and POS is using the same cloud scale unit where the channel DB is. It clearly runs the same retailSDK as well. So what is the eCommerce looking for in customization of the CRT? Or can it not handle any customization in the CRT and retailServer side? I have changed the IRequestTrigger to IRequestTriggerAsync to no avail. It fails on that too.
Here is the OnExecuted code of my CRT custom:
****
public void OnExecuted(Request request, Response response)
{
ThrowIf.Null(request, "request");
ThrowIf.Null(response, "response");
var productsList = ((EntityDataServiceResponse<ProductSearchResult>)response);
if (productsList == null)
{
return;
}
foreach (ProductSearchResult product in productsList)
{
string vWhse = request.RequestContext.GetChannelConfiguration().InventLocation;
decimal iQty = 0;
decimal rQty = 0;
decimal oQty = 0;
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>();
string vLoc = "";
if (extensions != null)
{
foreach (OrgUnitAvailability obj in extensions)
{
if (obj != null)
{
vLoc = obj.OrgUnitLocation.InventoryLocationId;
fList = obj.ItemAvailabilities;
if (fList != null)
{
foreach (ItemAvailability vI in fList)
{
if (vLoc == vWhse)
{
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);
}
}
***/
It has no problem with srchCriteria. but the moment I uncomment "EntityDataServiceResponse<OrgUnitAvailability> availResponse = request.RequestContext.Execute<EntityDataServiceResponse<OrgUnitAvailability>>((Request)availRequest);" then eCommerce fails. It is as if it cannot run another execute.
I don't get currently any explanation from Microsoft. AlI I get at this point is that this issue is caused by a custom product trigger.
"We are sure that the issue is coming from your customization, you will have to remove it on your sandbox/UAT environment and please let me know if the issue continues once you remove the customization, if so, you can report back to me but if the issue disappears we will not be able to continue with your support request."
Well it is obvious it is the custom. but what is not obvious is why it is working for POS but eCommerce has an issue. I can't get an explanation out of Microsoft to tell me if eCommerce cannot handle CRT customization. If it can, then why is it working for POS? It more looks to me that eCommerce can't handle custom to the CRT.
Did anybody else run into an issue like this? Is it possible for eCommerce to run an execute function inside an OnExecuted? Keep in mind that I did change it to run Async to no avail. I get the same behavior.