QuickBase API Cookbook v3 - Recipe #6
Create a daily history of the changes to a table
Copy records
You have records in a table and need to track changes to the records over time.
1) Copy the application using these menus in QuickBase: Go To, Miscellaneous, Copy without Data
2) From your copy of the application, use the menus in QuickBase to Export the table back to your original application. 
3) At this point, you should have an empty table in your application that has exactly the same structure as your original table.
4) In your new table, add a text field that will contain the Record ID# of records from the original table.
5) You can now modify the script below to copy records from the source table to the target table:

require 'QuickBaseClient'
require 'Date'

if ARGV.length < 4
   puts "\n Usage: ruby copyrecords.rb <username> <password> <sourceTableDBID> <targetTableDBID>\n"
   puts "\n e.g. ruby copyrecords.rb myusername mypassword xxxxxxxxx yyyyyyyyy\n."
   puts "\n Adds copies of records from a main table to a history table."
   puts "\n This script assumes the field names match between the two tables.\n"
   exit
end

qbc = QuickBase::Client.new( ARGV[0], ARGV[1] )

#Uncomment the following line to see the data being sent to QuickBase and returned from QuickBase
#qbc.printRequestsAndResponses = true 

#fieldNames is the list of fields values you want to copy
#Change the list to match your real field names.

fieldNames = Array.new
fieldNames = [ "Record ID#", "Date Updated", "Title", "Description", "MutipleChoiceField" ]

puts "Adding copies of all source table records to target table"

#fieldValues is a hash of arrays of field values from all records in the source table
qbc.getSchema( ARGV[2] )
fieldValues = qbc.getAllValuesForFields( ARGV[2], fieldNames )
numRecs = fieldValues[ "Record ID#" ].length

#for each record (i) retrieved from the source table...
(0..numRecs.to_i-1).each{ |i|
   
   #clear previously uploaded field values
   qbc.clearFieldValuePairList
   
   #loop through the list of field values for record i
   fieldValues.each { |fieldName,valueArray|
   
       # get the value of fieldName in record i
       value = valueArray[i]
       
       # copy the field name - it will need to be changed for some fields
       targetFieldName = fieldName.dup
       
       # date fields must be converted from the numeric version to a format that can be sent back to QuickBase
       value = qbc.formatDate( value, nil, true ) if targetFieldName == "Date Updated"
       
       # put the source table's Record ID# in a different field in the target table
       # (you could do this for any field that has a different name in the target table)
       targetFieldName = "Source Record ID #" if targetFieldName == "Record ID#"
       
       # the values of multiple choice fields must be in the list of available choices
       if targetFieldName == "MutipleChoiceField"  
          qbc._fieldNameAddChoices( targetFieldName, value ) 
       end
       
       # add the field value to the list of fields to be uploaded to the target table
       qbc.addFieldValuePair( targetFieldName, nil, nil,  value ) 
   }
   
   puts "Adding record #{i} of #{numRecs.to_i-1}"
   qbc.addRecord( ARGV[3], qbc.fvlist )
   
   # print any error message from QuickBase, if there was one
   if !qbc.requestSucceeded
     qbc.printLastError
   end
   
}

# signout of QuickBase
qbc.signOut

copyrecords.rb
Ruby wrapper for QuickBase HTTP API One-Click Ruby Installer for Windows
Created on Sept. 29, 2006 at  9:27 PM (PDT). Last updated by Quick Base on Oct.  1, 2006 at  2:25 PM (PDT). Owned by Quick Base.
Quick Base
Quick Base
Show fields from Show fields from Show fields from a related table
Report Name *
Description
Reports and Charts Panel
Each table has a panel listing its reports and charts, organized in groups.
Please wait while your new report is saved...
Field label
Column heading override
Justification
What does auto mean?
Fields in:

Fields to Extract:

Name for the new table:
Items in the new table are called:

When you bring additional fields into a conversion, Quickbase often finds inconsistencies. For example, say you're converting your Companies column into its own table. One company, Acme Corporation, has offices in New York, Dallas and Portland. So, when you add the City column to the conversion, Quickbase finds three different locations for Acme. A single value in the column you're converting can only match one value in any additional field. Quickbase needs you to clean up the extra cities before it can create your new table. To do so, you have one of two choices:

  • If you want to create three separate Acme records (Acme-New York, Acme-Dallas and Acme-Portland) click the Conform link at the top of the column.
  • If the dissimilar entries are mistakes (say Acme only has one office in New York and the other locations are data-entry errors) go back into your table and correct the inconsistencies—in this case, changing all locations to New York. Then try the conversion again.

Read more about converting a column into a table.

We're glad you're interested in doing more with Quickbase!

Now we need to make you official before you share apps or manage your account.

Verifying your email lets you share Quickbase with others in your company.

Your work email
Your company