7 Replies Latest reply on Feb 17, 2017 4:37 AM by bmarimuthu RSS
    bmarimuthu Apprentice

    How to arrange my entries using json??

    I have created a new service "Mlist_service" in "Mlist_datatable" added up having field definitions "entities_name" as primary key. Then I wrote json script in my service using snippet"Add/update datatable entry". when I export my data and entities and use it in another system,the order of my entries in "entites_name" is changed.

    so  how can I arrange my entries in "entities_name" in ascending order??

      • Re: How to arrange my entries using json??
        jamesm Creator

        Can you simple add a sort parameter to your service that returns the records? i.e. QueryDataTableEntries with a query parameter such as:

         

        var query =
        {
          "sorts": [
          {
              "fieldName": "entities_name"
          }
          ]
        }
        


        See this page for more details: Query Parameter for Query Services

         

        Or is the field you're trying to sort a JSON object and you are wondering why it loses its sorting? If so, please note the definition of JSON according to www.json.org:

         

        "An object is an unordered set of name/value pairs"

         

        Therefor you should never rely on the ordering of elements.

          • Re: How to arrange my entries using json??
            bmarimuthu Apprentice

            Getting error as "Invalid QUERY value. Please make sure it's a valid JSON string"

            • Re: How to arrange my entries using json??
              bmarimuthu Apprentice

              I used "add/update datatable entry" snippet and using service I add entries in to it and impleted it in mashup using list. In my system it works fine. But when I export and use, the order has changed. Is any other simple way for this to do??

                • Re: How to arrange my entries using json??
                  anna Creator

                  Hi Bavithraa,

                  So you mean in your mashup,firstly you call your service which add or update datatable entry and then you will call your service QueryDataTableEntries with event "ServiceInvokeCompleted" to refresh the Grid(Or list widget you mentioned above?).

                  As what I did locally, you could create a new service say, it's called QueryCustom, and in the QueryCustom service, you could code like this:

                  var query =

                  {

                  "sorts": [

                  {

                  "fieldName": "f1"

                  }

                  ]

                  };

                   

                  var params = {

                      maxItems: undefined /* NUMBER */,

                      values: undefined /* INFOTABLE*/,

                      query: query /* QUERY */,

                      source: undefined /* STRING */,

                      tags: undefined /* TAGS */

                  };

                   

                  // result: INFOTABLE dataShape: "undefined"

                  var result = me.QueryDataTableEntries(params);

                  And here is the screenshot for my code:

                  So in your mashup, after you add/update your data table every time, you call the QueryCustomer service, the Grid should be refreshed and ordered ascending. The reason you should not use QueryDataTableEntries directly in your mashup is that there is no sorting options input in the query parameter(it only has filter not sorting).

                  Please let us know if this works and if further assistance needed.

                  Thanks,

              • Re: How to arrange my entries using json??
                anna Creator

                Dear Bavithraa,

                Did James answer your question? As James advised, please consider to use the Query parameter in your services and sorting options in it should solve your issue, and please test  on your side with the script James provides and it's already Ascending order by default so no need to configure Ascending parameter in sorting again. Please let us know if you need further help.

                Thanks!

                • Re: How to arrange my entries using json??
                  Ankit Gupta Ninja

                  Hi Bavithraa Marimuthu, If this issue is resolved; i would suggest you to mark the correct answer or share your answer so that other members know that this issue is resolved.