Time & Expense Copart strangeness when updating with a function

We are implementing a new application to handle the scheduling and and operation of our rotational ovens since that is something that Kinetic just can’t do.

We are pulling the applicable jobs from Kinetic into the new application via a BAQ.
As the new app completes operations on the job, it will report that back to Kinetic via a function library that creates a time and expense entry.

I’m struggling to get the function to deal with coparts to replicate the results seen when entering copart quantities in the smart client.

The base function begins by adding a new Time Detail record for the Job/Operation and saving it. Then if coparts are involved, I have a for-each loop that calls a function to up the copart Production quantity and save the change for each copart.

This function works perfectly when the Time Detail record created is the first record created for the LaborHead. The labor quantity is set correctly on the LaborDtl record and the part completed is automatically received into inventory on the Job.

The head scratcher is that if the function is run to create another Time Detail (LaborDtl) record for the same header, the copart quantities update, but the labor quantity is not set on the LaborDtl record.

I’ve been able to compensate for this by adding another step sequence to the function to also update the labor quantity on the LaborDtl record.

In testing, this has allowed the coparts to be received to inventory on the job manually and the job can be closed. However when the Time Detail entry is for a quantity that completes the operation and completes the job, those fields aren’t toggled to true.

I’ve done multiple trace comparisons and haven’t been able to find anything to explain why the second Time Detail added to the LaborHead via the function doesn’t behave the same as the first.

Any suggestions?