Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Workflow » How to redirect to another url in batch ?
Re: How to redirect to another url in batch ? [message #4224 is a reply to message #4222] Thu, 05 June 2014 11:05 Go to previous messageGo to previous message
AJM is currently offline  AJM
Messages: 2363
Registered: April 2006
Location: Surrey, UK
Senior Member
Your script is totally wrong as you have copied the code from an ADD1 pattern which is designed to accept input from an HTML form. A batch job can only accept input from a disk file which can contain any number of records. I have tried the following script in my test environment and it works perfectly:

This script is called 'takeon_person(batch).php' with a task_id of 'takeon_person(batch)':
<?php
//*****************************************************************************
// this uploads data from a CSV file to the XAMPLE database
//*****************************************************************************

$stdout = '../logs/person_csv.html';

ini_set('include_path', '.');
require 'std.batch.inc';

batchInit(__FILE__);

$task_id = basename($task_id, '.php');  // replaces 'batch'
$role_id = 'DEMO';                      // replaces 'batch'

$filename = 'files/upload/person.csv';

$dbobject = RDCsingleton::getInstance('x_person');

// do not fail if record already exists when inserting
$dbobject->no_duplicate_error = TRUE;

require('std.csv.class.inc');
$CSVobj = new csv_class($dbobject);

// read first line to obtain delimiter (comma, tab or pipe)
$CSVobj->open_read($filename);
check_errors($CSVobj);

$count = 0;
while ($data = $CSVobj->read_file()) {
	// give this array to the database object
	$dbobject->startTransaction();
    $data = $dbobject->insertRecord($data);
    check_errors($dbobject);
    $dbobject->commit();
    $count ++;
    $key = 'person_id= ' .$data['person_id'];
    if ($dbobject->numrows == 0) {
    	$output = "<p>$count : $key already exists</p>\r\n";
    } else {
        $output = "<p>$count : $key created</p>\r\n";
    } // if
    if (!$result = fwrite($stdouth, $output)) {
        trigger_error("Cannot write to file $stdout", E_USER_ERROR);
    } // if
    $output = '';
} // while
check_errors($CSVobj);

$output = "<p>$count records processed.<p>";
if (!$result = fwrite($stdouth, $output)) {
    trigger_error("Cannot write to file $stdout", E_USER_ERROR);
} // if

fclose($handle);

batchEnd();

?>


The person.csv file has the following format:

"person_id","first_name","last_name","nat_ins_no","pers_type_id ","node_id","star_sign"
"test_01","test_01","test_01","test_01","MAD","2", "CAN"



 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Having problem starting a case
Next Topic: Work item assignments
Goto Forum:
  


Current Time: Mon Nov 04 11:45:38 EST 2024

Total time taken to generate the page: 0.01285 seconds