AnsweredAssumed Answered

export to CSV works on site but not ondemand

Question asked by ted moriello on Jul 31, 2018

I have created an action file on an on site backup instance.  It works perfectly on site.  I created an admin link which hits this URL:

 

#bwc/index.php?module=SF1_SalesmanFinder&action=exportsalesmanfinder

 

A white screen pops up in the "Salesman Finder" custom module and then a CSV dumps into my browser of the raw DB data.  When I load this action file onto the ondemand instance and click the link, I get the chrome frown face inside the Custom module and this text:

 

The webpage at https://<the site url is here>/index.php?module=SF1_SalesmanFinder&action=exportsalesmanfinder&bwcFrame=1 might be temporarily down or it may have moved permanently to a new web address.

 

In console i get this:

Uncaught SecurityError: Blocked a frame with origin "https://<site url is here>" from accessing a cross-origin frame. at https://<site url is here>/cache/javascript/base/components_8d0f662f1dd52337d0a8ef794100e111.js on line 34310

 

 

Here is my code that works perfectly on site:

 

ob_end_clean();
if(!defined('sugarEntry'))define('sugarEntry', true);
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=export_SalesmanFinder.csv');

require_once 'modules/Configurator/Configurator.php';

global $db, $sugar_config;

$db_host_name = $sugar_config['dbconfig']['db_host_name'];
$db_user_name = $sugar_config['dbconfig']['db_user_name'];
$db_password = $sugar_config['dbconfig']['db_password'];
$db_name = $sugar_config['dbconfig']['db_name'];

$conn = mysql_connect($sugar_config['dbconfig']['db_host_name'], $sugar_config['dbconfig']['db_user_name'], $sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name'], $conn);

$query = sprintf("SELECT * FROM sf1_salesmanfinder, sf1_salesmanfinder_cstm WHERE sf1_salesmanfinder.id = sf1_salesmanfinder_cstm.id_c AND sf1_salesmanfinder.deleted = '0'");
$result = mysql_query($query, $conn) or die(mysql_error($conn));

$row = mysql_fetch_assoc($result);
if ($row) {
echocsv(array_keys($row));
}
/*
* output data rows (if atleast one row exists)
*/

while ($row) {
echocsv($row);
$row = mysql_fetch_assoc($result);
}
/*
* echo the input array as csv data maintaining consistency with most CSV implementations
* - uses double-quotes as enclosure when necessary
* - uses double double-quotes to escape double-quotes
* - uses CRLF as a line separator
*/


function echocsv($fields)
{
$separator = '';
foreach ($fields as $field) {
if (preg_match('/\\r|\\n|,|"/', $field)) {
$field = '"' . str_replace('"', '""', $field) . '"';
}
echo $separator . $field;
$separator = ',';
}
echo "\r\n";
}

Outcomes