Business Central Command Line
PutData
First, we’ll let BCCL remember our credentials to BC and URL to avoid having to retype these parameters:
BCCL -w "http://bcserver:7047/BC/WS/CRONUS/Codeunit/bccl" -u demo -p jf394584jfefjg --remember
Now, we’ll create a simple file with a few new customers, in this let’s use csv:
Number,Name
"1000","Erik Hougaard"
"2000","Peter Hansson"
"3000","Mads Mathiesen"
Since there are more fields in the Customer table then the two we have in this file, we need a mapping file to link our fields to database fields. If you don’t specify a mapping file, you must supply a file with all the fields from the table.
BCCL -t mapping -s table=18 -o table18.mapping.json
First, we remove the field we don’t need and then we’ll activate all the validations.
{
"Customer": [
{
"FieldNo": 1,
"FieldName": "No.",
"MappedName": "Number",
"Validate": "true"
},
{
"FieldNo": 2,
"FieldName": "Name",
"MappedName": "Name",
"Validate": "true"
}
],
"ValidateOnInsert": "true",
"ValidateOnModify": "true"
}
Now we call BCCL, with the putdata tasktype, specify the input file with -i customers.csv, if you forget to specify the -f parameter, BCCL will try to figure out the format from the filename. We specify the mapping file and the parameter table=18.
bccl -t putdata -i customers.csv -m table18.mapping.json -s table=18
The result is returned as json, tallying up the total operations:
{
"Table": 18,
"Inserted": 3,
"Modified": 0
}
A quick look in BC find the three new customers:
If we remove the No. column from the mapping file, so there’s only one column mapping (even though there still two columns in the file)
{
"Customer": [
{
"FieldNo": 2,
"FieldName": "Name",
"MappedName": "Name",
"Validate": "true"
}
],
"ValidateOnInsert": "true",
"ValidateOnModify": "true"
}
And run the import again:
bccl -t putdata -i customers.csv -m table18.mapping.json -s table=18
The result is three new customers, this time, customer number are created from the number series:
XML
If your file is XML, you need to supply the -r parameter, to tell BCCL where the record is located in the XML file. Example, if your XML is looking like this:
12200
Adatum Corporation
.....
Then the parameter should -r /Customer/Record to tell BCCL that the Record structure under Customer is the repeating structure.
bccl -t putdata -i customers.xml -m table18.mapping.json -s table=18 -r /Customer/Record
Stub Records
BCCL can insert stub records in related tables, to fulfill relational requirements, read about stub records here.
SQL Support
If you specify the file type as SQL, GETDATA can write the data into a table on a Microsoft SQL Server. This video shows how to use SQL Server with BCCL: