Configuration parameter set in commerce parameter

  If you want to get the value of the configuration parameter set in commerce parameter in commerce runtime, then below is the code you execute,

            string parameterValue  = string.Empty;

            GetConfigurationParametersDataRequest getConfigurationParametersDataRequest = new GetConfigurationParametersDataRequest(requestContext.GetPrincipal().ChannelId);

                var retailConfigurationParameters = await requestContext.ExecuteAsync<EntityDataServiceResponse<RetailConfigurationParameter>>(getConfigurationParametersDataRequest).ConfigureAwait(false);

                RetailConfigurationParameter retailConfigurationParameter = retailConfigurationParameters.ToList<RetailConfigurationParameter>().SingleOrDefault<RetailConfigurationParameter>((RetailConfigurationParameter c) => c.Name.Equals("YOUR PARAMETER NAME", StringComparison.OrdinalIgnoreCase));

if (retailConfigurationParameter != null)

                {

                    parameterValue = retailConfigurationParameter.Value;

                }

 

·       In the first line, we create an Out-of-Box (OOB) request GetConfigurationParametersDataRequest that takes the channelId from the requestContext.


·       In the second line, we execute the request and obtain the response in retailConfigurationParameters.


·       In the third line, we convert the retailConfigurationParameters into a list and filter for the required parameter value using the LINQ SingleOrDefault method.

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