LiveCloud Forums
Query cloud, modify a single key, update cloud - Printable Version

+- LiveCloud Forums (https://forums.livecloud.io)
+-- Forum: General (https://forums.livecloud.io/forumdisplay.php?fid=1)
+--- Forum: Code Samples (https://forums.livecloud.io/forumdisplay.php?fid=7)
+--- Thread: Query cloud, modify a single key, update cloud (/showthread.php?tid=391)



Query cloud, modify a single key, update cloud - mark_talluto - 04-01-2020

This code will demonstrate how to query cloud data for a specific key and value. It will then update that value for all the matching records and update the cloud.

Code:
on mouseUp
    local tInputA, tOutputA, tUpdatedLastName, tTableID
   
    put "Franklin" into tUpdatedLastName
    put cdb_tableID("Agents") into tTableID
   
    --QUERY FOR MATCHING DATA
    put cdb_query("lastName","=","Talluto","Agents","cloud","recordList") into tOutputA
   
    --REPEAT THROUGH EACH RECORD AND UPDATE THE 'lastName' VALUE FOR EACH RECORD FROM THE QUERY
    repeat for each line xRecordID in tOutputA
         put tUpdatedLastName into tInputA[tTableID][xRecordID]["lastName"]
    end repeat
   
    --UPDATE DATA IN THE CLOUD
    cdb_batchUpdate tInputA, "cloud"
end mouseUp