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?