Fetching fields from a Form and placing them in a Subform

Fetching fields from a Form and placing them in a Subform

I Have a form called Employees where their Name, Role and Rate is specified.
I have another form called Project Details with a Subform in it called Project Workers where we specify the workers working on the project.

The Project Workers subform has a lookup (drop down) field called Employees, when you click on it and pick an employee from the drop down list, the Rate of this worker is pulled from the Employees form and displayed in a single line field called Rate.




I have written a script to do this but the problem with it is that is works ONLY on the first employee added. When adding a second employee, it does not work, i.e. the Rate does not show. The script is:

y = input.Project_Workers.Employees.Rate;
input.Project_Workers.Rate = y;
z = input.Project_Workers.Employees.Role;
input.Project_Workers.Role = z; 

Please note that the workflow is based on Subform On Add Row.



Please help. Thank you.