Undefined offset: 0

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!”);
}

Re: Undefined offset: 0

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.

Re: Undefined offset: 0

Its probably a problem with {dataset[0][0]}. Its returns no value so you got a message undefined offset
try:

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