Here is how I do this:
if (event.type == Blockly.Events.CREATE && manualAction) {
var parentBlock = workspace.getBlockById(event.blockId);
//add switches to the inputs of the BK
if (parentBlock.type == "bk") {
for (var i = 0; i <= 15; i++) {
var childBlock = workspace.newBlock('px');
if (i <= 9) {
var parentConnection = parentBlock.getInput("I.D0" + i).connection;
childBlock.setFieldValue('BK01.I.D0' + i, 'SwitchAddress');
} else {
var parentConnection = parentBlock.getInput("I.D" + i).connection;
childBlock.setFieldValue('BK01.I.D' + i, 'SwitchAddress');
}
childBlock.initSvg();
childBlock.render();
var childConnection = childBlock.outputConnection;
parentConnection.connect(childConnection);
}
}
...