jqGrid Access Extra Information - json

I have a dynamically created jqGrid with a custom formatter. I need to be able to access some information that is not in a grid column within the formatter. My problem is that the rowObject seems to contain only the information from the columns and nothing else, even though the JSON data has an extra attribute.
My JSON looks like:
{"rows":
[
{"cell":["637","Alice","Test","01\/01\/1980",""],"id":"637","patient_id":"637"},
...
{"cell":["635","Alice","Test","01\/01\/1980",""],"id":"635","patient_id":"635"},
],
"form_id":"3",
"records":"35",
"total":2,
"goto_patient_sidebar":"1",
"totalRecords":"35",
"dynamicFilters":"",
"listName":"Patients",
"page":1,
"recordsReturned":25,
"columns":
[
{"id":"75","field_id":"2","zmr_list_id":"13","alias":"Last Name",
"sortorder":"0","reference_field_id":"90","show_date":"0","show_time":"0"},
{"id":"76","field_id":"1","zmr_list_id":"13","alias":"First Name",
"sortorder":"1","reference_field_id":"90","show_date":"0","show_time":"0"},
{"id":"77","field_id":"25","zmr_list_id":"13","alias":"DOB",
"sortorder":"2","reference_field_id":"90","show_date":"1","show_time":"0"},
{"id":"78","field_id":"47","zmr_list_id":"13","alias":"Phone Number",
"sortorder":"3","reference_field_id":"90","show_date":"0","show_time":"0"}
]
}
For each row, I need to access the patient_id from the JSON. The data for the columns of each row is contained in the 'cell' for each row. The rowObject seems to contain only the information in each cell attribute of the JSON. How can I access patient_id without it being rendered in the column?

In the data the values of patient_id are always the same as the id. I suppose that there can be different (if patient_id are equal to id you can see the information in the custom formatter already). You can implement what you need in at least three ways:
You add an hidden column (having the property hidden:true) which will represent the patient_id. You move the information about the patient_id in the JSON input inside the "cell" array.
You place the information about the mapping between id and patient_id as the part of userdata which you will include in the JSON (see here for more information).
You use data parameter of the loadComplete event handle. The data parameter will contain full JSON data posted from the server. You can get the information which you need from the data and save it somewhere. Then you get the saved information from the custom formatter.
One more small remark about your JSON data. Currently you use items like
{
"cell": [
"637",
"Alice",
"Test",
"01\/01\/1980",
""
],
"id": "637",
}
(if we forget about the patient_id). It means that you send id information twice: one as the part of the column and second time for the first column of the grid. If you would include key:true setting in the definition of the first grid column and add jsonReader: {cell:""} you could make the JSON data in more compact where the row item would be in the array form
[
"637",
"Alice",
"Test",
"01\/01\/1980",
""
]

Add a hidden column for the extra data.

Related

Sorting a JSON object in SQL

I have a SQL variable which stores the following JSON object:
{"name": "Dan", "country": "Japan", "job": "manager"}
My goal is to sort the object based on the keys alphabetically and return it
{"country": "Japan", "job": "manager", "name": "Dan"}. The keys will vary for different json objects.
Unfortunately, I am unable to use OpenJson because of compatibility issue and it may stay that way. So I tried using JSON_TABLE command. My overall goal is to:
Create a table with two columns, keys and values, keys will hold all the keys in the json object, whereas values will hold the corresponding value for the key in that row.
Use order by key to return the result in sorted way
Return the result in a json object format
However, I am getting stuck at the first step. I created two variables to store the json arrays for the keys and values separately using JSON_KEYS and JSON_EXTRACT. Then, I combined them into another variable, which has the following structure:
{key: ['name', 'country', 'job'], value:['Dan', 'Japan', 'manager']}. Finally, I used JSON_Table on it with the hope of completing step 1. But since they are sibling arrays, JSON_TABLE produced two columns where total number of rows are 6 instead of 3. I do not know how to get past this.
Is there any simpler solution than this?
Thanks in advance.
This is because of you set type JSON of column. So it converts automatically in alphabetically order. If you want to save data of json array as you insert(not rearrange in alphabetically). you need to change column type JSON to TEXT. it will work.
Thank you.

How to retrieve and update JSON value In LogicApp using 'For Each'

Background:
I wish to loop through, retrieve and update items within my document
I wish to locate and loop through values within an array, locate nested values and then update them using LogicApps. I know I am on the right path, I just need a little assistance.
1.Here is the document. I wish to loop over A (it has many records in it) and retrieve all of the
categories.
"A":
[
{
"category": "1"
}
]
2.Once I retrieve the categories, I wish to loop over each one of the categories I find and then update their id and status
"category":"1"
"box":
[
{
"id": "update"
"status": "update"
}
]
My approach and what I have done:
I believe I have to do a 'For Each' loop over the A's.
I am just not sure how to write in the logicApp that I want to retrieve all the "category" fields and then the fields within the box field.
Then once I obtain all the "category" fields, I must update the id and status within this array with
a string.
I want to change
"id": "update" to "id" : "number"
and change
"status": "update" to "status": "linked"
I believe I must: initialize, parse, and do a For Loop
I believe I must: initialize, parse, and do a 'For Each' Loop, but how do I tell the logicapp I wish to grab the "category" part of the "A" since its nested, and then once I have the "category" part to then update the nested fields of "id" and "status" within that?
Any help is great
You have two options to do the editing.
First is the traditional Logic Apps way:
Use a set of working variables and the setProperty() function to update values as you go along. One variable to hold the portion you are currently editing and an array to hold the work done so far. Since you are working with nested arrays, you'll need two sets of variables- one set for the array inside "A" and one for the array inside "box". In order to update child properties, you just nest setProperty() calls: setProperty(<object>['<parent-property>'], '<parent-property>', setProperty(<object>['parentProperty'], '<child-property>', <value>)).
If you haven't already, you may want to take a look at this post, as it has a similar premise, though is a bit simpler in structure: Updating Json Array in LogicApp
Second option is to use the inline code action
In your case, I would probably go this route as the number of actions required drops significantly, making the app easier to read and reducing the cost. As long as your data is not too large, you could do all of your edits in a single action and simply output the result. If you want to keep some of the structure or you have a large object, you could keep elements of both- use the loop on your "A" array and then make your changes to that iteration inside Javascript.

A field reference identifier must not have the form of a qualified name

I have a json file with the following structure:
{
"0.0.1":{
"version":"0.0.1",
"date_created":"2014-03-15"
},
"0.1.2":{
"version":"0.1.2",
"date_created":"2014-05-21"
}
}
As you can see the whole json file contains just one object which is a map in which each key is the version number and the value is a new map with version and date_created properties.
I want to use Apache Drill to get a list with two columns: version and date_created
But since the keys contain dots (e.g. "0.0.1") Drill throws the following error:
Error: SYSTEM ERROR: UnsupportedOperationException: Unhandled field reference "0.0.1"; a field reference identifier must not have the form of a qualified name (i.e., with ".").
... when running a query like this:
SELECT KVGEN(t.*) FROM dfs.`D:/drill/sample-data/myjsonfile.json` AS t;
By the way, how do you tell KVGEN to process the WHOLE ROW since the row object is the actual map we want to convert?
Any ideas about how to overcome this problem?
UPDATE:
Are all the map keys always different? yes they are. But I think that even in the case they were not, Drill should process them anyway and whenever it would find a duplicate, it should keep the last one (which normally is supposed to be the most recent one for most cases).
The main problem is that the JSON file contains ONLY one big object so there is only 1 record (row) and all its properties are the actual keys to each version data. So there are NO subproperties to navigate to when using KVGEN; the idea is that KVGEN processes the WHOLE record object and not a subproperty of it.
As someone has requested to get more sample data, here it is below:
{
"0.0.1":{
"version":"0.0.1",
"date_created":"2014-03-15"
},
"0.1.2":{
"version":"0.1.2",
"date_created":"2014-05-21"
},
"0.1.5":{
"version":"0.1.5",
"date_created":"2014-05-29"
},
"0.1.7":{
"version":"0.1.7",
"date_created":"2014-06-13"
},
"1.0.0":{
"version":"1.0.0",
"date_created":"2014-07-05"
},
"1.1.0":{
"version":"1.1.0",
"date_created":"2014-09-02"
}
}

How do I connect a django rest framework json query result to dgrid/OnDemandGrid

My JSON store (django rest framework) returns keys for "count", "next", "previous", and "results".
"count" is the number of rows available.
"next" is the url for the next page of results (e.g. ids 26-50).
"previous" is the url for the previous page of results (null in this case since this is the first page of results).
The "results" key contains the actual data objects I'd like to display in the OnDemandGrid.
How do I connect the "results" key data collection to the grid? Thank you for your help in advance.
The returned JSON ( collection: new Rest({target: '/api/events'?format=json'),}) ) looks like this:
{
"count":1411,
"next":"http://localhost/api/events/?format=json&page=2",
"previous":null,
"results": [
{"id":1,"event_type":"02","event_at":"2015-03-31T12:53:41Z","machine_id":1,"revs":4342,"color":5,"heads_info":"using http","tag":1,"hidden":false},
{"id":2,"event_type":"02","event_at":"2015-03-31T12:53:41Z","machine_id":1,"revs":4342,"color":5,"heads_info":"using http","tag":1,"hidden":false},
...
{"id":25,"event_type":"02","event_at":"2015-03-31T12:54:01Z","machine_id":1,"revs":4342,"color":5,"heads_info":"using http","tag":1,"hidden":false},
]
}
It looks like you're trying to use this service with dstore/Rest, but that has some specific expectations of the server request and response:
The response must report the list of items in one of the following ways:
Respond with a top-level array of items
Respond with an object with an items property whose value is an array of items
The response must report the total number of items in one of the following ways:
If the response is an object, you may include a total property in the object
Otherwise, you must include a Content-Range header (in the format X-Y/Z items, where the Z is of primary importance)
The request must support being informed of the range of items it should request out of the total result set via one of the following mechanisms:
start and count GET parameters (specified to the store instance via rangeStartParam and rangeCountParam)
Range headers (by setting useRangeHeaders: true)
Otherwise, by default, the store will pass a limit GET parameter in the format limit(count,start) (or just limit(count) if start is 0)
If your server can't fulfill these requirements (e.g. it sounds like it has quite different requirements regarding ranging, since it uses pages instead), you're going to need to think about extending/implementing a custom store.

How to update nested data from a PUT request

Suppose we have a Invoice that is saved in a draft state in a RDBMS. The invoice has three line items. A rest client gets the invoice, and modifies the line items.
GET /invoice/123
{
"InvoiceId" : "123",
"lineitems":
[
{ "id":"A", "qty":"5"},
{ "id":"B", "qty":"5"},
]
}
Assume user modifies the invoice as follows;
Changes quantity of Item A
Removes Item B.
Adds new item C.
The result is:
{
"InvoiceId" : "123",
"lineitems":
[
{ "id":"A", "qty":"10"},
{ "id":"D", "qty":"5"},
]
}
The net change is that a line has been deleted, a line has been updated, and a line has been added.
User then saves the draft invoice, which results in a PUT request.
PUT /invoice/123
What is the best strategy to update the line items on the server?
Keep in mind that deleteing all line items and creating them from scratch will loose any meta data on those lines (Created by, Created date, last modified by...)
Thanks,
The PUT method requests that the enclosed entity be stored under the supplied Request-URI.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
Think of PUT as replace. The state of the resource in the PUT request should be the resulting state of the resource if it is accepted.
If you want to add/remove/update specific elements you should look into using PATCH.