Using a variable in event's sql statement makes the code buggy

I have a master form and a detail form.
This is how the application is supposed to work:
the user enters a value in variable A in master form.
when the user adds a record to detail form, Variable B is supposed to be updated with Variable A,
and then Variable C (which is still in the same record) uses the value in variable B in the where clause of its sql statement (variable C is of type select).

now in order to update the variable B I added an event onLoadRecord in detail form with this code:

$currentID = {ID};

//$sql = “select VariableA from masterTable where ID= $currentID”;
$sql = "select VariableA from masterTable where ID= 18 ";

sc_lookup(rs,$sql);
if ({rs} === false)
{
echo “Access error.”;
}
elseif (empty({rs}))
{
echo “Select command didn’t return data”;
}
else
{
//echo {rs[0][0]};
{VariableB} = {rs[0][0]};
};

now, if you see i have two sql statements , one of them commented out. When the second sql statement runs, i get exactly what i want -> when adding record, Variable B is updated and Variable C is correctly using it to get the right results.

but when i use the first sql (which has a variable), this is what i get.(i checked many diffrent types of adding a variable to my sql statement, none of them work)

and

I have debug turned on so i can see the sqls that get sent.
as you can see both the sqls in both cases say: select CustomerName from workorder where WOID = 18

This is the select sql statement for variable C in case anyone needs it

SELECT PartDescription
FROM customerparts
where Vendor = “{VariableB}”
ORDER BY PartDescription

but i dont know that why i get diffrent results when i get the correct sql statement whether I type number 18 or if i use a variable with value 18.

Please help, im so lost.

Where do you get the field {ID} assigned from in your detail?

  • did you set up a master/detail relationship in the master?
  • did you use an Application link ?

image

I do have a master detail relationship and i dont use a application link. ID is also the ID of the the master form.

Hi anaZandi!
In your detail, use a global variable using value of master, this must solve for you

🚀 Scriptcase 9.12 is now available! Check out the new features here 👉🚀 Next Monday (02/24), Scriptcase 9.12 will be released! Check out the new features before anyone else 👉