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

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Unanswered

CRT custom works in POS but fails in eCommerce

(0) ShareShare
ReportReport
Posted on by 1,453

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.

I have the same question (0)
  • Retha Profile Picture
    1,453 on at
    RE: CRT custom works in POS but fails in eCommerce

    Microsoft helped me in the end.

    First eCommerce can't work optimally with SQL server searches because of performance, it can be too slow to retrieve the data. So they switched to Azure search. This needs to be turned on in D365 for eCommerce to use Azure search and it is MANDATORY for the use of eCommerce.

    Retail and commerce > Headquarters setup > Parameters > commerce parameters: Configuration parameters tab:

    ****

    These cloud-powered search capabilities are available starting in version 10.0.8. Ensure that under Commerce Parameters > Configuration Parameters there is an entry for "ProductSearch.UseAzureSearch set to 'true'".

    ****

    This document indicates the exact name you have to use, there is no dropdown to select it from, so copy and paste to make sure you do not misspell it:

    docs.microsoft.com/.../cloud-powered-search-overview

    After the above setting was added, I had to run distribution schedule 1110. Give it some time to get to the channel DB and whatever eCommerce use to read it.

    This fixed eCommerce and I was able to see products but it broke Retail POS which suddenly didn't show any of our custom on the product search.

    The reason for this is that for environments where the Azure search flag is NOT turned on, the product search in POS calls request GetProductSearchResultsDataRequest, and that is what I used in the SupportedRequestTypes. The moment I turned on Azure search, it switched to request GetProductSearchResultsServiceRequest for POS and eCommerce. So be aware of this. Because we have an environment with eCommerce turned on and others where it is not turned on at the moment, I had to add both requests in the SupportedRequestTypes.

    Also, when you do not want certain custom to be run by eCommerce, the flag to look for to skip the custom in a request/response trigger custom is called IsOnlineStore:

    if(request.Requestcontext.GetChannelConfiguration().IsOnlineStore())

    {

    return;

    }

    Hope this will help somebody else that has the same problem that I had.

  • Juliet Zhu Profile Picture
    on at
    RE: CRT custom works in POS but fails in eCommerce

    Hi Retha,

    I will leave this question for other community members (developers) to answer. Let's see if anybody has experienced the same and can advise for you anything.

    Thank you for using Microsoft Dynamics Communities,

    Juliet Zhu

    SR SUPPORT ENG

    Microsoft Dynamics AX / Dynamics 365 Commerce

    If my information answers your question please click 'Yes' against "Did this answer your question?" to help other community members. 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 159 Super User 2025 Season 2

#2
Yng Lih Profile Picture

Yng Lih 150

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 104 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans