Issue Material via a Function, but part bin doesn't update

I’m writing a function to issue material to a job via a function so an external program can easily make the transaction. I initially wrote everything in the function using the IssueReturnSvcContract, the issue transaction correctly creates a PartTran record and updates the JobMtl Record, but the PartBin record doesn’t have the new onhand qty.

I took a step back and triggered the issue from data directive on UD40.

Writing to UD40 worked fine from the UI and from REST, my material was issued and part bin correctly updated. I then updated my function to write to UD40 using the widgets. My BPM fired and issued the material, but the PartBin wasn’t updated.

Any thoughts?

Does the call for the part bin update use session info? I don’t believe that session info is always passed in through rest.

I’ll take a look at the session info.

Words cannot express how confused I am. The part bin record does eventually get updated but it takes a long time.

Here was my test:
I started with 100 parts in my bin. I ran Refresh PartBin QOH from PartTran to make sure my part bin record was clean.
7:30 AM: I triggered my BPM though a function and issued a material. The job was updated and the transaction showed in PartTran.
PartBin still shows 100 on hand.

7:32AM: Run Refresh PartBin QOH from PartTran and PartBin was updated to 99.

I left part tracker open for the rest of the morning, occasionally retrieving the part bins.
12:53PM: Part Bin is still at 99.
2:23PM: Part Bin has changed to 98!!! :scream:
2:25PM: Run Refresh PartBin QOH from PartTran and PartBin was updated to 99.

I checked part transaction history tracker and there have been no transactions on this part since 7:30AM.

So my initial transaction took between 4 and 6 hours to complete???

Other random info: My function supports returns and those update part bin immediately. This is on Kinetic 2021.2.3.

I’m going to go back to the “Old Fashioned” way and post my command to UD40 instead of using the function.

The spooky thing is triggering the BPM through the function gives different results than triggering the BPM though the UI or REST.

There is a deferred update that happens for some processes. And yes, it will MESS you up! Search the forum for deferred update and you’ll see some posts about it.

1 Like

That did it! I added this to my function.

var context = Ice.Services.ContextFactory.CreateContext<ErpContext>();

Erp.Internal.Lib.DeferredUpdate libDeferredUpdate = new Erp.Internal.Lib.DeferredUpdate(context);
libDeferredUpdate.UpdPQDemand();

Note: I tried adding it to my BPM first since currently the function was triggering the BPM. Adding it to the deferred update to my BPM didn’t help, but adding it at the end of my function fixed it.

Now I’m wondering how often I need to include that in functions. Do I need to end every function with a “take care of those extra tables right now” command?

I guess it’s time to put the code back in the function where it belongs instead of the BPM.