Exercise – Create a new CRT trigger

Completed

In this exercise, you will implement a trigger and then register the extension, debug the CRT, and validate the extension.

Implement a trigger

To implement a trigger, complete the tasks as shown in the following code example.

  1. Implement IrequestTriggerAsync.

  2. Specify SupportedRequestTypes to define the request types that the trigger must be implemented for.

  3. Write a trigger implementation in the OnExecuting method if business logic must be run before the request is addressed.

  4. Write a trigger implementation in the OnExecuted method if business logic must be run after the request is addressed.

    using Microsoft.Dynamics.Commerce.Runtime;
    using Microsoft.Dynamics.Commerce.Runtime.DataServices.Messages;
    using Microsoft.Dynamics.Commerce.Runtime.Messages;
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    public class GetCustomerTriggers : IRequestTriggerAsync
    {
       /// <summary>
       /// Gets the supported requests for this trigger.
       /// </summary>
       public IEnumerable<Type> SupportedRequestTypes
       {
           get
             {
               return new[] { typeof(GetCustomerDataRequest) };
             }
       }
    
       /// <summary>
       /// Post trigger code.
       /// </summary>
       /// <param name="request">The request.</param>
       /// <param name="response">The response.</param>
       public async Task OnExecuted(Request request, Response response)
       {
          //Custom logic
    
         // The only stub to handle async signature 
            await Task.CompletedTask;
        }
    
        /// <summary>
        /// Pre trigger code
        /// </summary>
        /// <param name="request">The request.</param>
        public async Task OnExecuting(Request request)
        {
            // custom logic 
            await Task.CompletedTask;
        }
    }
    

Register the extension

To register the extension, complete these tasks:

  1. Copy and paste the extension library to the ...\RetailServer\webroot\bin\ext folder and then update the commerceRuntime.ext.config file with the custom extension library information under the composition section. In this example, Contoso.Commerce.Runtime.Services is the custom extension name.
  2. For the CRT extension to work in offline mode, update ...\Microsoft Dynamics 365\70\Retail Modern POS\ClientBroker\ext\CommerceRuntime.MPOSOffline.ext.config with the extension library information under the composition section.
  3. Copy and paste the extension library to ...\Microsoft Dynamics 365\70\Retail Modern POS\ClientBroker\ext.

Debug CRT

To debug CRT from Store Commerce, attach the CRT extension project to the w3wp.exe (IIS process for Retail server) process when Store Commerce is connected to the Retail server.

For offline mode, attach the CRT extension project to the dllhost.exe process.

Validate the extension

To validate the extension, complete these tasks:

  1. Sign in to Store Commerce.
  2. Search for any customer in Store Commerce and then go to the customer details. The preceding CRT request will be called.