• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confused about how to use "recordData" in Query
#1
Hi guys, this is probably a very dum question but what can I do...

According to the documentation the Output for a query using "recordData" as the "pResultFormat" parameter is:

(Array) - If pResultFormat is "recordData":
  • Output is an array where each key is a recordID of a record in the specified table that matches the query, with subkeys defined by the schema.
I'm confused as how to retrieve the Array elements as I don't know the recordIDs...

Using the Example of the documentation

recordData Output:
# tOutputA["87654321-abcd-1234-cdef-1234567890ab"]["cdb"] - metadata
#                                                  ["firstName"] - "Jenny"
#                                                  ["lastName"] - "Smith"
#                                                  ["age"] - 46
#                                                  ["income"] - 100000

Where do I get "87654321-abcd-1234-cdef-1234567890ab" from?

Moreover let's say the query returns 4 records, how do I navigate trough each of them?

Can you please provide a complete example? Many thanks


Thanks
To ";" or not to ";" that is the question
  Reply
#2
This is a great question. The data is returned to you as a LiveCode array. I took a picture of the result I got from running some test code I put together. You can see that the data returned contains three matching records from my query.

I added a few little things that may be useful in what you can do once you have the data. In this case, I am modifying one of the keys on each record and then batch updating the changes to the cloud.

Here is the code that generated the results:


Code:
local tOutputA, tKeys, tTableID, tUpdatedDataA
     put cdb_query("firstName","starts with","M","Agents","cloud","recordData") into tOutputA
    
     --GET THE RECORD IDS
     put the keys of tOutputA into tKeys
    
     --GET TABLE ID
     put cdb_tableID("Agents") into tTableID
    
     --CRAWL THROUGH EACH RECORD TO GET ACCESS TO THE DATA RETURNED
     --WRITE THE FIST NAME FOR ALL RETURNED RECORDS INTO A LIST FIELD
     repeat for each key xRecordID in tOutputA
          --put tOutputA[xRecordID]["firstName"] & lf after field "list"
          
          --MODIFY THE INCOME KEY BY ADDING 1000 TO THE EXISTING VALUE
          add 1000 to tOutputA[xRecordID]["income"]
          
          --PREPARE THE UPDATED DATA TO BE UPLOADED
          repeat for each key xKey in tOutputA[xRecordID]
               put tOutputA[xRecordID][xKey] into tUpdatedDataA[tTableID][xRecordID][xKey]
          end repeat
     end repeat
    
     --UPLOAD THE UPDATED DATA TO THE CLOUD
     cdb_batchUpdate tUpdatedDataA, "cloud"


Attached Files Thumbnail(s)
       
  Reply
#3
Thanks Mark, it is pretty obvious now.
To ";" or not to ";" that is the question
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)