Update field when adding row to subform

Update field when adding row to subform

Hi,

I'm having trouble getting a script to work when trying to add rows to a subform.  I have a subform called Tasks on a main form called Jobs and when I add a new row I need a field called Task_Unit in the subform to populate when the lookup field SOR_Code is added/updated.  I have attached a screenshot of the subform showing how the Task Unit value is duplicating from the initial row (regardless of how many rows I add) , rather than taking the correct value from the lookup relationship (field Rate_Per) for each row and here is the code I'm running On the main form Jobs > on user input in the subform Tasks > field SOR_Code:

x = SOR_Codes[ID == input.Tasks.SOR_Code];
row.Task_Unit=x.Rate_Per;

I've looked for a solution and have tried a few things suggested in previous topics but can't get this to work.  Is anyone able to help please?