Getting data from another table into my form

I have a form connected to database table (batches) and within this form there is a select lookup field named “Variety Name” which looks up values from another table (Inventory) and i want when a selection is made for other fields in my form to be filled with data from the Inventory table.

So far i added Ajax on blur and tried on change the following code:

sc_lookup(dataset, “SELECT Variety_Code, Size FROM inventory WHERE Variety_Name = ‘{Variety_Name}’”);

if(!empty({dataset}[0][0]))
{
{Variety_Code} = {dataset [0][0]};
{Size} = {dataset [0][1]};
sc_set_focus(‘Variety_Code’);
}
else
{
{pitem_desc} = “”;
{pitem_unit_price} = 0;
sc_set_focus(‘Variety_Code’);
}

and nothing happens and i’m seeing this error below.

SQL ERROR’s:
Method sc_field_2_onBlur: “SELECT Variety_Code, Size FROM inventory WHERE Variety_Name = ‘{Variety_Name}’”
()

Have you try this Ajax Processing from Form Select Datatype?

Regards,
Ihsan Kusasi

Did you add the parameter {Variety_Name} on the Ajax method?

What value are you getting from de lookup, the code (Variety_Code) or Variety_Name?

Thank you for the replies, i actually did some tidying of my database and made this work with the following code.

$variety = {varietyname}; // this is actually inventory_id

if (!empty($variety)) {

$sql = "SELECT varietycode, size, trayarea
        FROM inventory
        WHERE inventory_id = '$variety'";

sc_lookup(ds, $sql);

if (isset({ds[0][0]})) {
    {varietycode} = {ds[0][0]};
    {size}        = {ds[0][1]};
    {trayarea}    = {ds[0][2]};
} else {
    {varietycode} = '';
    {size}        = '';
    {trayarea}    = '';
}

}

if(!empty({dataset}[0][0])) debe ser if(!empty({dataset[0][0]})) fíjate en donde se ponen las llaves {}