Load data into c3 type from console

#1

How do I load a CSV file into a c3 type from console?

1 Like

#2

In the console, go to Tools and then Load File. Select the csv file you want to import.
The header needs to match fields on the c3 type you want to create: e.g. (parent.id, timestamp, quantity.value)

The console will return something like this:

loaded myFile.csv (text/csv) into C3.console.LoadedFiles[0]

Then run the following commands:

var file = Extract.create(Extract.make({id : "myFile", name : "My File", contentType:'text/csv'}));
var csv = C3.console.LoadedFiles[0].readString();
Extract.writeString(file, csv, true);

var contentRef = DeepRef.make({moduleName:'bulkdataimport', typeName:'Extract', id : "myFile"});
var importDataSpec = ImportDataSpec.make({content:contentRef});
MyType.importData(importDataSpec);

This will return stats / errors on the import data job.

You can check that data was successfully loaded: MyType.fetch({...})

1 Like