You are here:  » Importing Records Customisation

Support Forum



Importing Records Customisation

Submitted by Keeop on Thu, 2010-02-11 19:27 in

Hi David,

I hope you can help with this one. I am trying to put some code in admin.php for manipulating records at import. Now, I'm seeing some strange behaviour whereby if I try and set one field to a particular value, any other blank fields are also assigned this value for some reason. i.e. if I use this code:

if (trim($record["FIELDS/FIELD/NAME@1"]) === "size")
{
  $record[$admin_importFeed["field_B"]] = $record["FIELDS/FIELD/VALUE@1"];
}

..instead of just 'Field_B' being written in the DB with the specified value, any other fields that have not taken a specific value are also assigned with the value of '$record["FIELDS/FIELD/VALUE@1"]'.

I've come across this before and it's stumped me and previously I've had to create separate variables to deal with it. i.e.

$fieldB = $record["FIELDS/FIELD/VALUE@1"];

...and then written '$fieldB' to the database rather than '$record[$admin_importFeed["field_B"]]' but in this instance I'd rather not have to do this. So, any help why this is behaving this way would be most appreciated.

Cheers.
Keeop

Submitted by support on Fri, 2010-02-12 08:27

Hi Keeop,

If $admin_importFeed["field_B"] is empty then it will be updating the null element of $record; which is why every field that has not been assigned a record will take on the value of $record["FIELDS/FIELD/VALUE@1"]. Assigning a separate value would be the best aproach in this case...

Cheers,
David.

Submitted by Keeop on Fri, 2010-02-12 12:08

Hi David,

I'm really trying to avoid doing it that way as I may need to work on the $record later on and I can then use a generic solution for any field. I have tried using ISSETs but to no avail either:

$record[$admin_importFeed["field_B"]] = (isset($record["FIELDS/FIELD/VALUE@1"])?trim($record["FIELDS/FIELD/VALUE@1"]):"");

This still gives me the same problem. Could you help me out please in doing it this way so I can still refer to $record further along in the script rather than assigning new variables instead?

Cheers.
Keeop

Submitted by support on Fri, 2010-02-12 15:25

Hi Keeop,

One option would be to create a "virtual" field for it; so before your code above, try something like:

if (!$admin_importFeed["field_B"])
{
  $admin_importFeed["field_B"] = "%FIELDB%";
}

...and that will prevent overwriting the null ("") value...

Hope this helps!

Cheers,
David.

Submitted by Keeop on Fri, 2010-02-12 19:44

Hi David,

I'm not quite sure how it works, but it most certainly does! Thanks a lot for that.

Cheers.
Keeop

Submitted by Keeop on Fri, 2010-02-12 19:49

Ah, spoke too soon! It doesn't seem to be importing most of the records any more. Any ideas as to why?

Cheers.
Keeop

Submitted by support on Fri, 2010-02-12 21:44

Hi Keeop,

Could you email me your modified includes/admin.php and I'll take a look...!

Cheers,
David.