Storing Form Data to google sheet using Reactjs - reactjs

I want to upload all of my form data to google sheet. I tried on it but still can't store data on google sheet.
Here my Gsheet Api Call
{
"requests": [
{
"repeatCell": {
"range": {
"startRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"endRowIndex": 1,
"sheetId": 0
},
"cell": {
"userEnteredValue": {
"stringValue": "Adnan1",
"stringValue": "Adnan2",
"stringValue": "Adnan3",
"stringValue": "Adnan4"
}
},
"fields": "*"
}
}
]
}
Using this i update only one cell i know it's due to dimension but is there any way to store all of my form data to gsheet. Thank You

You're using RepeatCellRequest which is intended to repeat the same value in the selected range of cells. You could use a UpdateCellsRequest and use the rows field to set the values. The below example sets 3 rows values to the first column:
{
"requests": [
{
"updateCells": {
"range": {
"startRowIndex": 0,
"startColumnIndex": 0,
"endColumnIndex": 1,
"endRowIndex": 3,
"sheetId": 0
},
"rows": [
{
"values": [
{
"userEnteredValue": {
"stringValue": "Adnan1"
}
}
]
},
{
"values": [
{
"userEnteredValue": {
"stringValue": "Adnan2"
}
}
]
},
{
"values": [
{
"userEnteredValue": {
"stringValue": "Adnan3"
}
}
]
}
],
"fields": "*"
}
}
]
}

Related

React final forms how to add child forms

Have the sandbox with working React forms array
https://codesandbox.io/s/react-final-form-field-arrays-react-beatiful-dnd-as-drag-drop-forked-uz24z?file=/index.js:5933-6061
Which in result of click on the add hotspots and generate the data tree as
{
"toppings":[
],
"customers":[
{
"id":4,
"firstName":"name",
"lastName":"lastname"
},
{
"id":5,
"firstName":"Clark",
"lastName":"kent"
}
],
"hotspots":[
{
"hotspotId":6,
"positionY":"Xhostspotforcustomer1",
"positionX":"Yhostspotforcustomer1"
}
]
}
But I need hotspots to be added as children of customer when click on the Add Hotspot button (to same index of the values.customers array) like
{
"toppings":[
],
"customers":[
{
"id":4,
"firstName":"name",
"lastName":"lastname",
"hotspots":[
{
"hotspotId":6,
"positionY":"XhostspotforcustomerID4",
"positionX":"YhostspotforcustomerID4"
},
{
"hotspotId":7,
"positionY":"more XhostspotforcustomerID4",
"positionX":"new YhostspotforcustomerID4"
}
]
},
{
"id":5,
"firstName":"Clark",
"lastName":"kent",
"hotspots":[
{
"hotspotId":8,
"positionY":"XhostspotforcustomerID5",
"positionX":"YhostspotforcustomerID5"
}
]
}
],
}
The Add hotspot is added on line 174 of index.js
How to modify the code to add hotspots per customer separately ?
you need to combine customer field name with hotspot name:
when you do push/pop:
push(`${name}.hotspots`, /*...*/)
//...
pop(`${name}.hotspots`)
also in FieldArray field name:
<FieldArray name={`${name}.hotspots`}>
Demo: https://codesandbox.io/s/react-final-form-field-arrays-react-beatiful-dnd-as-drag-drop-forked-wivwu?file=/index.js
Result:
{
"toppings": [],
"customers": [
{
"id": 4,
"firstName": "name",
"lastName": "lastname",
"hotspots": [
{
"hotspotId": 6,
"positionY": "Customer4-Y1",
"positionX": "Customer4-X1"
},
{
"hotspotId": 7,
"positionY": "Customer4-Y2",
"positionX": "Customer4-X2"
}
]
},
{
"id": 5,
"firstName": "Clark",
"lastName": "kent",
"hotspots": [
{
"hotspotId": 8,
"positionY": "Customer5-Y1",
"positionX": "Customer5-X1"
}
]
}
]
}

Build json builder with arrayJson in groovy

I am new in groovy and I want to construct a json object with the builder
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{ "match": { "content": "scontent" } },
{ "match": { "title":"stitle" } }
]
}
},
{
"bool": {
"should": [
{ "match": { "a1": "v1" } },
{ "match": { "a2":"v2" } },
... and so on ...
{ "match": { "an":"vn" } }
]
}
}
]
}
},
"highlight": {
"fields": {
"content":{}
}
}
}
I search a lot of on other posts on stackoverflow and I write this code
So I did this but no way to get what I want :
JsonBuilder builder = new JsonBuilder()
def body = builder {
from Lib.or(qQuery.start, 0)
size Lib.or(qQuery.num, 10)
query {
bool {
must [
{
bool {
should [
{ match { content 'scontent' } },
{ match { title 'stitle' } }
]
}
},
{
bool {
should myVals.collect {[
'match' : { it.key it.value }
]}
}
}
]
}
}
highlight {
fields {
content {}
}
}
}
Thanks for any help !
I think you can make this work with the JsonBuilder as is, but it is usually easier to create the data structure using maps and lists (which is what the builder outputs) in groovy as you have more control there.
Example code:
import groovy.json.*
def data = [
query: [
bool: [
must: [
[bool:
[should: [
[match: [ content: 'scontent']],
[match: [ title: 'stitle']]
]]
],
[bool:
[should: [
[match: [ a1: 'v1']],
[match: [ a2: 'v2']],
[match: [ vn: 'vn']]
]]
]
]
]
]
]
println JsonOutput.prettyPrint(JsonOutput.toJson(data))
produces:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"content": "scontent"
}
},
{
"match": {
"title": "stitle"
}
}
]
}
},
{
"bool": {
"should": [
{
"match": {
"a1": "v1"
}
},
{
"match": {
"a2": "v2"
}
},
{
"match": {
"vn": "vn"
}
}
]
}
}
]
}
}
}
I did not include your full json as it takes up some space, but the structure is there. Note the use of lists ([valueA, valueB]) vs maps ([someKey: someValue]) in the data structure.
Granted this makes the JsonBuilder less than 100% useful but I haven't seen any concise ways of including lists of large json objects in a list within the structure. You can do:
def json = JsonBuilder()
json.query {
bool('list', 'of', 'values')
}
but for larger structures as list elements I would say go with the lists and maps approach.

How to Update nested Array in RethinkDB using ReQL

I have a question on Updating the array in RethinkDB. My JSON structure looks like below.
{
"LOG_EVENT": {
"ATTRIBUTES": [
{
"ATTRIBUTE1": "TYPE",
"VALUE": "ORDER"
},
{
"ATTRIBUTE2": "NUMBER",
"VALUE": "1234567"
}
],
"EVENT_CODE": [
{
"CODE_NAME": "EVENT_SAVED",
"EVENT_TIMESTAMP": "2015-08-18T00:58:12.421+08:00"
}
],
"MSG_HEADER": {
"BUSINESS_OBJ_TYPE": "order",
"MSG_ID": "f79a672b-f15e-459d-a29b-725486d6401f",
"DESTINATIONS": "3"
}
},
"id": "0de3117e-12dd-4d10-a464-dff391a4513f"
}
Here, I am trying to Update a new event inside my event code
{
"CODE_NAME": "MESSAGE_DELIVERED_TO_APP2",
"EVENT_TIMESTAMP": "2015-08-18T12:58:12.421+08:00"
}
My final JSON will look like below,
{
"LOG_EVENT": {
"ATTRIBUTES": [
{
"ATTRIBUTE1": "TYPE",
"VALUE": "ORDER"
},
{
"ATTRIBUTE2": "NUMBER",
"VALUE": "1234567"
}
],
"EVENT_CODE": [
{
"CODE_NAME": "EVENT_SAVED",
"EVENT_TIMESTAMP": "2015-08-18T00:58:12.421+08:00"
},
{
"CODE_NAME": "MESSAGE_DELIVERED_TO_APP2",
"EVENT_TIMESTAMP": "2015-08-18T12:58:12.421+08:00"
}
],
"MSG_HEADER": {
"BUSINESS_OBJ_TYPE": "order",
"MSG_ID": "f79a672b-f15e-459d-a29b-725486d6401f",
"DESTINATIONS": "3"
}
},
"id": "0de3117e-12dd-4d10-a464-dff391a4513f"
}
Can you help on the ReQL query ?
Tried below, but not working
r.db("test").table("test1").get("0de3117e-12dd-4d10-a464-dff391a4513f")("LOG_EVENT")('EVENT_CODE').update(function(row) {
return {EVENT_CODE: row('EVENT_CODE').map(function(d) {
return r.branch(d.append({
"CODE_NAME": "MESSAGE_DELIVERED_TO_APP2",
"EVENT_TIMESTAMP": "2015-08-18T00:58:12.421+08:00"
}), d)
})
}} )
well here is the code which updates the nested fields of object residing inside an array
r.db('DB').table('LOGS')
.get('ID')
.update({
EVENT_CODE: r.row('EVENT_CODE')
.changeAt(1, r.row('EVENT_CODE').nth(1)
.merge({"CODE_NAME": "MESSAGE_DELIVERED_TO_APP2"}))
})

AngularJS - json file parse

I'm having trouble getting to object in json file.
I'm using
.controller("ListController", ["$scope", "$http", function($scope, $http){
$http.get('../scripts/bbtv.json').success(function(data) {
$scope.artists = data;
});
}])
The data gets in the variable, but I can't access any object of it. Here is part of the json file. For example how to print out {{programmeField.titleField.valueField}} ?
{
"channelField": [
{
"displaynameField": [
{
"valueField": "bTV"
}
],
"idField": "BBTV"
}
],
"programmeField": [
{
"titleField": [
{
"langField": "BULG",
"valueField": "Тази сутрин"
}
],
"subtitleField": [],
"creditsField": {
"moderatorField": [
"Антон Хекимян"
]
},
"categoryField": [
{
"langField": "BULG",
"valueField": "Информационно предаване"
},
{
"langField": "BULG",
"valueField": "Сутрешен блок"
}
],
"languageField": {
"valueField": "BULG"
},
"lengthField": {
"unitsField": 1,
"valueField": "180"
},
"videoField": {
"presentField": "yes",
"colourField": "yes",
"aspectField": "4:3",
"qualityField": "800x600"
},
"audioField": {
"presentField": "yes",
"stereoField": "no",
"dolbyDigitalField": "no",
"dolbySurroundField": "no"
},
"startField": "20151216063000 +0200",
"stopField": "20151216093000 +0200",
"channelField": "BBTV",
"clumpidxField": "0/1",
"_photos": [
{
"_id": "5f38a2ab2fedd6b0e48da60b833bb4ddb69d3a1c",
"_url": "***.jpg",
"_type": "Letterbox"
}
],
"_deleted": false,
"_id": "189397717",
"_contentId": 45207610,
"_broadcastdate": "20151216"
}
}
JSON is a transport format. Once it's decoded, it's a native data structure, like any other structure. Since you're in JS, use JS conventions, and follow the bracketing/bracing. Note the labelling on the objects/arrays below:
data = { "channelField": [
a b
{ "displaynameField": [
c d
{ "valueField": "bTV"
e
}
],
"idField": "BBTV"
data.channelField[0].displaynameField[0].valueField -> "bTV"
a b c d e
Since your "programmeField" and "titleField" are array, use programmeField[0].titleField[0].valueField
In future you can copy your json to http://jsonviewer.stack.hu/ and the click on the Viewer tab.

Get object hit when searching array in Elasticsearch

I am trying to get an object out of a JSON array that is stored in elasticsearch. The layout is like this:
[
object{}
object{}
object{}
]
What I need for when I do a search and it hits on one of these objects, to get the specific object it matches to. Currently, using the java API I am searching with:
QueryBuilder qb = QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery("text", "pottery").boost(5)
.minimumShouldMatch("1"));
SearchResponse response = client.prepareSearch("stuff")
.setTypes("things")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(qb)
.setPostFilter(filter)//.setHighlighterQuery(qb)
.addField("places.numbers")
.addField("name")
.addField("city")
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();
But this will just return the whole object that I hit or when I tell it to return the field "places.numbers" it will only return the first object in the "palces" array, not the one that was matched in the query.
Thank you for any help!
There are a couple of ways to handle this. I would probably do it with a nested type and inner hits, given what you've shown in your question, but it could also probably be done with the parent/child relationship.
Here is an example with nested docs. I set up a simple index like this:
PUT /test_index
{
"mappings": {
"parent_doc": {
"properties": {
"parent_name": {
"type": "string"
},
"nested_docs": {
"type": "nested",
"properties": {
"nested_name": {
"type": "string"
}
}
}
}
}
}
}
Then added a couple of simple documents:
POST /test_index/parent_doc/_bulk
{"index":{"_id":1}}
{"parent_name":"p1","nested_docs":[{"nested_name":"n1"},{"nested_name":"n2"}]}
{"index":{"_id":2}}
{"parent_name":"p2","nested_docs":[{"nested_name":"n3"},{"nested_name":"n4"}]}
And now I can search like this, using "inner_hits":
POST /test_index/_search
{
"query": {
"nested": {
"path": "nested_docs",
"query": {
"match": {
"nested_docs.nested_name": "n3"
}
},
"inner_hits" : {}
}
}
}
which returns:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 2.098612,
"hits": [
{
"_index": "test_index",
"_type": "parent_doc",
"_id": "2",
"_score": 2.098612,
"_source": {
"parent_name": "p2",
"nested_docs": [
{
"nested_name": "n3"
},
{
"nested_name": "n4"
}
]
},
"inner_hits": {
"nested_docs": {
"hits": {
"total": 1,
"max_score": 2.098612,
"hits": [
{
"_index": "test_index",
"_type": "parent_doc",
"_id": "2",
"_nested": {
"field": "nested_docs",
"offset": 0
},
"_score": 2.098612,
"_source": {
"nested_name": "n3"
}
}
]
}
}
}
}
]
}
}
Here's the code I used to test it:
http://sense.qbox.io/gist/ef7debf436fec2a10097ba2106d5ff30ff8d7c77

Resources