Update CS Pack Ship To - Function Exception

Hoping for some insight on why I keep hitting a null reference.

Quick background - We create CS Packs that get placed on a Master Pack and Staged until ready for shipping. There are times when the Ship To changes after the CS Pack is created and sitting in a Closed stated prior to staging and in order to update the Ship To you need to Open the pack, delete the lines and then re-add the lines so it pulls in the new Ship To for the Line/Release.

What I did was create a function that retrieves the CS Pack into an original and a temporary tableset, so I have the original data. I then in the original tableset Open the pack, delete the lines and then loop through the temp tableset ShipDtl tables to re-add the lines back onto the original tableset. Then finally close the pack again.

First - is there a way I am not thinking of that is easier than this? I have never known of a better way to do it. If you update the Ship To on the Release it does not auto update any CS Packs, as expected since the Pack is a record onto itself and I have never been aware of any triggers in Epicor that performs this function.

Second - My function works for 1 Line CS Packs, it is when there is more than one line that I hit a Null reference error as I loop back through the temp tavleset. I have written to the Server log every piece of data that I can and everything is available, from what I can see. I even broke it out and created a second custom code block to handle a second line (do not loop in the first custom code block), so that I had a new tablesset for the original but hit the exact same null reference.

Tried to debug the function like a BPM but was not successful, not sure if there is a was to debug a function using Visual Studio.

Here is the Exception

c__DisplayClass12_0.b__0(CustShipSvcContract svc) in UpdateCloseCustPackShipToNum.cs:line 219 at Epicor.Functions.FunctionBase`3.CallService[TService](Action`1 action) in C:\_Releases\ICE\RL10.2.600.0FW\Source\Server\Internal\Lib\Epicor.Functions.Core\FunctionBase.Plugins.cs:line 60 at EFx.SALESORDER.Implementation.UpdateCloseCustPackShipToNumImpl.A002_CustomCodeAction() in UpdateCloseCustPackShipToNum.cs:line 250 at EFx.SALESORDER.Implementation.UpdateCloseCustPackShipToNumImpl.RunStep(Int32 workflowStep) in UpdateCloseCustPackShipToNum.cs:line 48 at Epicor.Functions.FunctionBase`3.Run() in C:\_Releases\ICE\RL10.2.600.0FW\Source\Server\Internal\Lib\Epicor.Functions.Core\FunctionBase.cs:line 90 at Epicor.Functions.FunctionBase`3.Run(TInput input) in C:\_Releases\ICE\RL10.2.600.0FW\Source\Server\Internal\Lib\Epicor.Functions.Core\FunctionBase.cs:line 75 at EFx.SALESORDER.Implementation.UpdateCloseCustPackShipToNumImpl.AdapterRun(Object[] input) in UpdateCloseCustPackShipToNum.adapter.cs:line 27 at Epicor.Functions.TransactionalAdapter.Run(Object[] input) in C:\_Releases\ICE\RL10.2.600.0FW\Source\Server\Internal\Lib\Epicor.Functions.Core\TransactionalAdapter.cs:line 36 at Ice.Internal.Task.ScheduledFunction.ExecuteFunction.RunFunction(IFunctionAdapter functionAdapter, Object[] parameters) in C:\_Releases\ICE\RL10.2.600.0FW\Source\Server\Internal\Task\ScheduledFunction\ExecuteFunction.cs:line 128 at Ice.Internal.Task.ScheduledFunction.ExecuteFunction.RunProcess(Int64 instanceTaskNum, String outputFileName) in C:\_Releases\ICE\RL10.2.600.0FW\Source\Server\Internal\Task\ScheduledFunction\ExecuteFunction.cs:line 71 at Ice.Core.TaskBase`1.StartProcess(Int64 instanceTaskNum, String outputFileName) in C:\_Releases\ICE\UD10.2.600.37FW\Source\Server\Internal\Lib\TaskLib\TaskBase\TaskBase.cs:line 83 at Ice.Hosting.TaskCaller.InnerExecuteTask(IceDataContext newContext) in C:\_Releases\ICE\UD10.2.600.37FW\Source\Framework\Epicor.Ice\Hosting\TaskCaller\TaskCaller.cs:line 117 at Ice.Hosting.TaskCaller.ExecuteTask() in C:\_Releases\ICE\UD10.2.600.37FW\Source\Framework\Epicor.Ice\Hosting\TaskCaller\TaskCaller.cs:line 59 at Ice.Lib.RunTask.BpmFriendlyTaskLauncher.Run(String sessionIdPrefix, IceContext db, Action taskRunner) in C:\_Releases\ICE\UD10.2.600.37FW\Source\Server\Services\Lib\RunTask\BpmFriendlyTaskLauncher.cs:line 63 at Ice.Services.Lib.RunTaskSvc.InnerRunTask(Int64 ipTaskNum, Boolean suppressTransaction) in C:\_Releases\ICE\UD10.2.600.37FW\Source\Server\Services\Lib\RunTask\RunTask.cs:line 452]]>

Thanks for any help,
Scott

Your method makes sense, as you can’t change the ship to on a pack if there are existing lines that loaded with the original ship to.

I find it best to get functions working first as a BPM triggered off something benign, eg the UDCodes table. Much easier to debug there than running functions looking for exceptions in log.

Probably a long shot but I’ve seen this before. For adding lines to the pack - when you do that, Epicor doesn’t like previous lines in your dataset. Before you call the update, your dataset should only have the header and the new line in it. No previous lines. This may be your case too. What I did is I stuck a GetByID to get the header without any lines in it (you can set the where clause for lines like PackLine<0 or something) and then called the GetNew for the new line. I did this for each line. Hope that helps.

Terry,

Thanks, had the same thought and already tried in a BPM and debugged in VS and see the same null reference but cannot determine what the null reference is, it is just not presenting itself. I was hoping maybe debugging a function with VS would give more info but I can’t seem to figure out how to do that.

Scott

I was doing GetById at a number of points to just to ensure I had a clean tableset and still get the error.

Thanks,
Scott