12-17-2019, 02:14 AM
Hi sid,
The code I provided will only work for a read. This is because the output for a batchQuery is slightly different than the output for a read. A batchQuery has two more layers in the output array, the tableID and the query index. The code below will massage the output of a batchQuery into the format for a datagrid.
cdb_tableKeys returns all the keys in a table. We repeat through each of these keys to get the data for all of the columns of a record like you want. As for tResultFormat, we want to use "recordData" in this case. "recordData" gives the entire record while "resultList" only gives the recordID of the records. We will fix the documentation to include the "into", thanks for pointing that out.
Hope this helps! Let me know if you have any question.
The code I provided will only work for a read. This is because the output for a batchQuery is slightly different than the output for a read. A batchQuery has two more layers in the output array, the tableID and the query index. The code below will massage the output of a batchQuery into the format for a datagrid.
Code:
local tInputA, tOutputA, tTableID, tKeys, tCount, tDataA, tRecordID
put cdb_TableID("testTable") into tTableID
put cdb_tableKeys("testTable") into tKeys
put "date" into tInputA[tTableID]["query2"]["key"]
put "<=" into tInputA[tTableID]["query2"]["operator"]
put "12/13/19" into tInputA[tTableID]["query2"]["value"]
put "date" into tInputA[tTableID]["query1"]["key"]
put ">=" into tInputA[tTableID]["query1"]["operator"]
put "12/01/19" into tInputA[tTableID]["query1"]["value"]
put cdb_batchQuery(tInputA,"cloud","logicalAND","recordData") into tOutputA
put 0 into tCount
repeat for each key xRecordID in tOutputA[tTableID][1]
add 1 to tCount
put tOutputA[tTableID][1][xRecordID]["cdb"]["cdbRecordID"] into tRecordID
repeat for each item xKeyName in tKeys
put tOutputA[tTableID][1][xRecordID][xKeyName] into tDataA[tCount][xKeyName]
end repeat
end repeat
cdb_tableKeys returns all the keys in a table. We repeat through each of these keys to get the data for all of the columns of a record like you want. As for tResultFormat, we want to use "recordData" in this case. "recordData" gives the entire record while "resultList" only gives the recordID of the records. We will fix the documentation to include the "into", thanks for pointing that out.
Hope this helps! Let me know if you have any question.