PDA

View Full Version : Undefined offset: 0



rapoportb
02-23-2011, 06:41 PM
I use the same script on OnBeforeUpdate and OnBeforeInsert events.
In both cases I have Error "Invalid Item!", but on onBeforeInsert I have also additional Error "Undefined offset: 0".

Below is the script I used.

sc_lookup(dataset, "select arbecd from CWMUDTA.initem where arcomp={M0COMP} and arbecd='{M0ITEM}'");

if (!{dataset[0][0]})
{
sc_error_message("Invalid Item!");
}

ScottMartin
02-23-2011, 10:01 PM
Several things to look at:

-echo your SQL statement to the form and see if it is valid.
-copy the echo'd statement to your DB manager and execute .. do you get a result?

Here is the code I used in projects:

$sql = 'SELECT ....';
sc_lookup(tbl_items,$sql);

if ({tbl_items} == false || empty({tbl_items}) ) {
return false;
} else {
return {tbl_items[0][0]} > 0 ? true : false;
}

Regards,
Scott.

Sztajer
02-24-2011, 07:11 AM
It`s probably a problem with {dataset[0][0]}. It`s returns no value so you got a message undefined offset
try:

if (empty({dataset}))
{
sc_error_message("Invalid Item!");
}