Listcsv Plugin

teoyh

Member
If i want to do a check for the csv import ;

I have this php code which i call from the Import Row PHP Code to do the check if there is already a record in the table I return false but the return false does not seem to prevent the record from being inserted.
Is there any other way to prevent the record from being inserted. I cannot choose overide as there may be other data already being added to the previous record.

class importStates
{
function Cleanup($importModel)
{
$db = FabrikWorker::getDbo(false, 3);
$listModel = $importModel->getModel();
$formModel = $listModel->getFormModel();
$sapno = $formModel->formData['stm_single_clocking___sapno'];
$wdate = $formModel->formData['stm_single_clocking___workdate'];
$recid = $formModel->formData['stm_single_clocking___id'];
$db->setQuery("SELECT id FROM single_clocking where sapno='$sapno' and workdate='$wdate'");
$id = $db->loadResult();
if($id!==''){
return false;
}
}


}

Thanks in advance :)
 
Do you return the value of your function call?

Like ...

return $inportStates->Cleanup($model);

-- hugh
I did not , i do notice that at the point of my check the record had not been inserted into the table yet. My attention is to do a check if the record exist, if yes then i will skip the record but i am not sure of how to do that.

So should i do this return $inportStates->Cleanup($model);

but what does it return just curious
 
Your "Import row php code" should return true or false. Returning false should skip that row. If you just call your Cleanup function (rather than putting "return" before the call), you aren't returning anything. The function returns a value, but it just gets ignored. You have to return the value your function returns.

Sent from my HTC6545LVW using Tapatalk
 
Your "Import row php code" should return true or false. Returning false should skip that row. If you just call your Cleanup function (rather than putting "return" before the call), you aren't returning anything. The function returns a value, but it just gets ignored. You have to return the value your function returns.

Sent from my HTC6545LVW using Tapatalk

Thanks for the hint , got what you mean I tested this and it work.

Basically I added a return in the import Row PHP Code

return.jpg

In my Cleanup , I will check if the id is not empty, if not empty mean that the record exist therefore i will need to return false which will then skip the record.

if(!empty($id)){
return false;
} else{
return true;
}

Thank you so much
 
From this wiki

http://fabrikar.com/forums/index.php?wiki/list-csv-list-plugin/

it explain that if we want to alter the record's data, we can use the following ;
$timein = $formModel->formData['stm_single_clocking___timein'];

I try to do the following but did not seem to work ;

if(strlen($timein)==4){
$formModel->formData['stm_single_clocking___timein']="";
}

Is there anything i am missing out ?

Thanks in advance :)
 
Are you sure that strlen() condition is applying? Have you debugged it, like put in a

echo "changing data";exit;

... inside the if to see if it's actually triggering.

-- hugh
 
Is there a way to first delete the group of record before i do a import so that I will not get a duplicate ;

I try to do a count so if $x=='' then i will do a delete first, but seem that $x is not retaining the count it is alway blank !

function Cleanup($importModel){
$x++;
$db = FabrikWorker::getDbo(false, 3);
$listModel = $importModel->getModel();
$formModel = $listModel->getFormModel();
$chartid = $formModel->formData[orgchart_item___chart_id'];
if($x==''){
$db->setQuery("delete from orgchart_item where chart_id='$chartid'");
$db->query();
}
if(strlen($chartid)==0){
return false;
}
}

Thanks in advance.
 
Declare $x as "static" ...

Code:
function Cleanup($importModel) {
   static $x = 0;
   ....
   $x++;
}

$x will then be set to 0 the first time the function runs, then retain whatever value you set it to after that.

-- hugh
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top