Fetch data from related form not working in a mainform/subform scenario

Fetch data from related form not working in a mainform/subform scenario

I have three forms: Orders (mainform) Order Items (subform) and Products. When i input the product ID at Order Item, a script trigered on user input fetches data from the related form Products to populate all the other fields of the Order Items.
It works fine if i enter the Order Item form the Order Item form, but if i enter the Order Item at the mainform Order where there is the subform Order Item, it doesn't work...
Please advise.

The script:
x  = Products [ID == input.ProductID];
input.Price = x.Price;
input.Color = x.Color
input. Type = x.Type 

Thanks!