cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How to arrange my entries using json??

bmarimuthu-2
1-Newbie

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??

1 ACCEPTED SOLUTION

Accepted Solutions
AnnaAn
13-Aquamarine
(To:bmarimuthu-2)

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,

View solution in original post

7 REPLIES 7
jamesm1
5-Regular Member
(To:bmarimuthu-2)

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.

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

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??

AnnaAn
13-Aquamarine
(To:bmarimuthu-2)

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,

Thanks!!

The problem got resolved.

AnnaAn
13-Aquamarine
(To:bmarimuthu-2)

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!

ankigupta
5-Regular Member
(To:bmarimuthu-2)

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.

Top Tags