Function using old version of value on User Input

Function using old version of value on User Input

Can anybody help me to understand this? I have the following (embarassingly) simple workflow that triggers on user input of Estimated_Fee:

input.Estimated_Fee_Per_Hour = input.Estimated_Fee / input.Estimated_Work_Time;

This works perfectly: when editing the record, I can see Estimated_Fee_Per_Hour change when I edit Estimated_Fee.

I want to convert this to become a function, which I have created as follows:

float ProjectsNTasks.CalculateEstimatedFeePerHour(Tasks task)
{
estimatedfeeperhour = input.task.Estimated_Fee / input.task.Estimated_Work_Time;
return estimatedfeeperhour;
}

This is called with the following workflow (also triggering on user input of Estimated_Fee):

input.Estimated_Fee_Per_Hour = thisapp.ProjectsNTasks.CalculateEstimatedFeePerHour(Tasks[ID = input.ID]);

However, for some reason, the function/workflow version doesn't use the 'live' version of Estimated_Fee when I update that field: it just uses the old value. I cannot see why the workflow version uses the live value but the function version doesn't.

Apologies that this is probably really simple but I just can't work it out despite much googling and debugging! (I have checked that the function is finding the right task and it appears to be acting correctly in every other way.)

Thanks in advance.