CSV Import Validation

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

CSV Import Validation

Post by angus » 2022-08-28 18:54

Hi everyone, I am trying to get some validation working on the csv import. Jsetzer has provided some guidance here - viewtopic.php?f=8&t=4858 but unfortunately this is beyond me. I have looked at ronthedev's plugin but this did not have any validation examples.

I have tried adding this in hooks/import-csv.php

Code: Select all

$transformFunctions['testtable'] = function($data, $options = []) {
			// new definition here
			// then you must return transformed data
			if($data['ContractID'] === '' ) {		
				exit;
			}
			if($data['Name'] === '' && $data['UnitIdentifer'] === ''  ) {		
				exit;
			}
			if(pkGivenLookupText($data['ContractID'], 'testtable', 'ContractID') == '' ) {		
				exit;
			}
			return $data;
		};
This worked up to a point but it fails on this part

Code: Select all

if(pkGivenLookupText($data['ContractID'], 'testtable', 'ContractID') == '' ) {		
				exit;
			}
has anyone got this working already that they could share with me?
AppGini 22.13

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: CSV Import Validation

Post by angus » 2022-08-30 13:43

just a quick update, this did not work. it actually interfered some how with the import process and stopped some fields from being entered, just blanks were being entered into the table for those records where I am using a lookup value so I have had to remove.

has anyone any examples on how to get the validation working?

Code: Select all

$transformFunctions['testtable'] = function($data, $options = []) {
			// new definition here
			// then you must return transformed data
			if($data['ContractID'] === '' ) {		
				exit;
			}
			if($data['Name'] === '' && $data['UnitIdentifer'] === ''  ) {		
				exit;
			}
			if(pkGivenLookupText($data['ContractID'], 'testtable', 'ContractID') == '' ) {		
				exit;
			}
			return $data;
		};
AppGini 22.13

Post Reply