Give this plugin a try, it fires onDocFormPrerender... creates a new document, sets the tv values, then redirects back to the document for edit. Works fine in my limited testing.
//<?php
// table names
$content_table = $modx->getFullTableName('site_content');
$tv_table = $modx->getFullTableName('site_tmplvar_contentvalues');
$template_id ='4';
$e = &$modx->Event;
switch ($e->name) {
case "OnDocFormPrerender":
// ensure this is a new document
if ($id == 0) {
// create the new document
// minimum required content fields
$fields = array(
'pagetitle' => time(),
'type' => 'document',
'template' => $template_id,
'createdby' => $_SESSION['mgrInternalKey'],
'createdon' => time(),
'contentType' => 'text/html'
);
/*
// all available content fields
$fields = array(
'introtext' => '',
'content' => '',
'pagetitle' => time(),
'longtitle' => '',
'type' => 'document',
'description' => '',
'alias' => '',
'link_attributes' => '',
'isfolder' => '',
'richtext' => '',
'published' => 0,
'parent' => 0,
'template' => $modx->config['default_template'],
'menuindex' => 0,
'searchable' => 0,
'cacheable' => 0,
'createdby' => $_SESSION['mgrInternalKey'],
'createdon' => time(),
'editedby' => '',
'editedon' => '',
'publishedby' => $_SESSION['mgrInternalKey'],
'publishedon' => '',
'pub_date' => '',
'unpub_date' => '',
'contentType' => 'text/html',
'content_dispo' => '',
'donthit' => '',
'menutitle' => '',
'hidemenu' => ''
);
*/
$modx->db->insert( $fields, $content_table);
// get the new doc id
$new_docid = $modx->db->getInsertId();
// populate the TV(s)
// copy/paste new sections for each TV
$fields = array(
'value' => 'Value for the 1st TV, 4th attempt',
'tmplvarid' => '1',
'contentid' => $new_docid
);
$modx->db->insert( $fields, $tv_table);
$fields = array(
'value' => 'Another Value for the 2nd TV, 4th attempt',
'tmplvarid' => '2',
'contentid' => $new_docid
);
$modx->db->insert( $fields, $tv_table);
// redirect back to the page to edit
$header = "Location: index.php?a=27&id=".$new_docid;
header($header);
}
break;
default: '';
return; // stop here - this is very important.
}