Call GetActiveProductPrice API in Commerce runtime dynamics 365

 In this blog, we learn how to call the GetActiveProductPrice API in the commerce runtime (CRT). 

  • We take ProductIds from cartLine but you also hardcode the ProductIds. 

                CartLine cartLine = ((AddCartLinesRequest)request).CartLines.FirstOrDefault();

                List<long> productIds = new List<long>();

                productIds.Add(cartLine.ProductId);

                ChannelConfiguration channelConfigs = request.RequestContext.GetChannelConfiguration();

  • Pass this ProductIds in the GetActiveProductPriceRequest and then execute the request.

                GetActiveProductPriceRequest getActiveProductPriceRequest = new                                     GetActiveProductPriceRequest()

                {

                    ProductIds = productIds,

                    DateWhenActive = new DateTimeOffset(DateTime.Now, TimeSpan.Zero),

                    Context = new ProjectionDomain(channelConfigs.RecordId, 0),

                    QueryResultSettings = new QueryResultSettings(new PagingInfo(1000)),

                    IncludeSimpleDiscountsInContextualPrice = true

                };

                GetActiveProductPriceResponse pricesResponse = await request.RequestContext.ExecuteAsync<GetActiveProductPriceResponse>(getActiveProductPriceRequest).ConfigureAwait(false);

Comments

Popular posts from this blog

Create custom workflow in D365 X++

Convert amount from one currency to another currency using X++

How to Create Extended Data Types (EDTs) in Finance and Operations of Dynamics 365 -- F&O Customization Part 2