Skip to main content

Notifications

Announcements

No record found.

Supply chain | Supply Chain Management, Commerce
Suggested answer

ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

Posted on by 20

in older versions of RetailSdk like in 10.0.10 or older ones, we used to have ODataQueryOptions to entertain the Query string parameters. and inside the ODataController action/method, we had a logic to get the QueryResultSettings object. For example, I had a custom controller like MyController inheriting the CustomersController, and in parameters of action/method of MyController, i used to be receiving the Query string parameters like this ODataQueryOptions<OrderShipments> options, and inside the action/method, i had a logic to get the page result of ordershipments like this

QueryResultSettings queryResultSettings = base.GetQueryResultSettings<OrderShipments>(options);


PageResult<OrderShipments> pageOrderShipments = base.ProcessPagedResults<OrderShipments> ustomerManager.Create(CommerceRuntime).GetOrderShipmentsHistory(key, queryResultSettings));


var pageOrderShipmentsNew = base.ProcessPagedResults<OrderShipments>(pageOrderShipments);

But in latest RetailSdk versions like 10.0.11 or later, the custom controller just has to implement the IController interface, and there i don't see any support to handle the Query string parameters, also, how Convert the PagedResult to PageResult in retail sdk version 10.0.11 or later version of retail sdk?

Your guidance will be highly appreciated. Thanks

  • RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    Welcome.

  • Suggested answer
    ToddB Profile Picture
    ToddB on at
    RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    Hi Humammad,

    Thank you for the update.

    The product team stated that they are working on ways to improve this, but there is no timeline as to when this will be done.

    Thanks again.

  • RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    Right. This is what seems to me so as well. But, I think there should be some other way around this problem also, and Microsoft must play it's role to come up with it's solution.

  • ToddB Profile Picture
    ToddB on at
    RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    Hi Muhammad,

    Here is what I have found out.

    The client would need to provide the top and skip parameters.

    Alternatively, they could send a PagingInfo object, which contains skip and top, or create another wrapping class for these parameters.

    Please let me know if you have any questions.

  • RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    Exactly, this is what I am emphasizing on.. The question that arises here is why this ODataQueryOptions has been explicitly removed? How will I entertain the proper paging on the PagedResult with the help of Top and Skip, unless i receive these fields/parameters as query string from the front end team?

  • Suggested answer
    ToddB Profile Picture
    ToddB on at
    RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    Hi Muhammad,

    What I was able to find out was that recently a change was made to remove the direct dependency of the extension code with the OData. It would be good if the extension code can migrate to this new model.

    NOTE: The old extension model should still continue to work and supported one year from the data of publishing 10.0.11.

    Create a new Retail Server extension API (Retail SDK version 10.0.11 and later)
    https://docs.microsoft.com/en-us/dynamics365/commerce/dev-itpro/retail-server-icontroller-extension

    The latest sample extension has explicitly removed using them:

     

    10.0.11 and higher:

     

        /// <summary>

        /// The controller to retrieve a new entity.

        /// </summary>

        [RoutePrefix("StoreHours")]

        [BindEntity(typeof(SampleDataModel.StoreDayHours))]

        public class StoreHoursController : IController

        {

            /// <summary>

            /// Gets the store hours for a given store.

            /// </summary>

            /// <param name="parameters">The parameters to this action.</param>

            /// <returns>The list of store hours.</returns>

            [HttpPost]

            [Authorization(CommerceRoles.Anonymous, CommerceRoles.Customer, CommerceRoles.Device, CommerceRoles.Employee)]

            public async Task<PagedResult<SampleDataModel.StoreDayHours>> GetStoreDaysByStore(IEndpointContext context, string StoreNumber)

            {

                QueryResultSettings queryResultSettings = QueryResultSettings.SingleRecord;

                queryResultSettings.Paging = new PagingInfo(10);

     

                var request = new GetStoreHoursDataRequest(StoreNumber) { QueryResultSettings = queryResultSettings };

                var hoursResponse = await context.ExecuteAsync<GetStoreHoursDataResponse>(request).ConfigureAwait(false);

                return hoursResponse.DayHours;

            }

        }

     

     

    10.0.11 or earlier:

     

            [ComVisible(false)]

            public class StoreHoursController : CommerceControllerAsync<SampleDataModel.StoreDayHours, long>

            {

                /// <summary>

                /// Gets the store hours for a given store.

                /// </summary>

                /// <param name="parameters">The parameters to this action.</param>

                /// <returns>The list of store hours.</returns>

                [HttpPost]

                [CommerceAuthorization(CommerceRoles.Anonymous, CommerceRoles.Customer, CommerceRoles.Device, CommerceRoles.Employee)]

                public async Task<PageResult<SampleDataModel.StoreDayHours>> GetStoreDaysByStore(ODataActionParameters parameters)

                {

                    if (parameters == null)

                    {

                        throw new ArgumentNullException(nameof(parameters));

                    }

     

                    QueryResultSettings queryResultSettings = QueryResultSettings.SingleRecord;

                    queryResultSettings.Paging = new PagingInfo(10);

     

                    var request = new GetStoreHoursDataRequest((string)parameters["StoreNumber"]) { QueryResultSettings = queryResultSettings };

                    var hoursResponse = await this.CommerceRuntime.ExecuteAsync<GetStoreHoursDataResponse>(request, null).ConfigureAwait(false);

                    PagedResult<SampleDataModel.StoreDayHours> hours = hoursResponse.DayHours;

                    return this.ProcessPagedResults(hours);

                }

           }

    Please let me know if this answers your question.

  • RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    The entire document does not describe about the handling of ODataQueryOptions in Retail Sdk 10.0.11, but I will thank you for sharing the above community to look for the answers relevant to my queries.

  • Suggested answer
    RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    Hi Muhammad,

    I think that the answers for your doubts and questions are in the following page in docs, you can find also some code samples, and you can compare the differences between 10.0.11 later and earlier:

    10.0.11 and later:

    docs.microsoft.com/.../retail-server-icontroller-extension

    10.0.11 and earlier:

    docs.microsoft.com/.../retail-server-extension

    Let me share with you a great Commerce/retail community in yammer Retail Interest group, where you can find also some questions and answers related with Dynamics 365 commerce.

    www.yammer.com/.../

  • RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    I still haven't had any answer for my issues.

  • RE: ODataQueryOptions in Retail Server with RetailSdk 10.0.11 or Later

    That's nice. Thank you Ramune Peckyte.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans