It’s a very simple BPM:
If the checkbox is checked, clear it and run the function. Inputs are values from the OrderHed, there is one output string for messages from the function.
The function is also fairly simple:
Customer.GetByID
If the ShipToMFBill already exists, update the info
Otherwise, Customer.GetNewShipToMFBill to get a new one, a series of Set Variable widgets
Then regardless of which method was used, Customer.Update to save changes
Finally, set the value of the return string
The Custom Code widget has the following code:
var thisShipToMFBill =
dsCustomer.ShipToMFBill
.FirstOrDefault(stmfb => string.Equals(stmfb.ShipToNum, ipShipToNum) && string.Equals(stmfb.PayBTFlag, ipPayBTFlag));
if (thisShipToMFBill == null) // ShipToMFBill not found
{
// Create it
blnSTMFBFound = false;
return;
}
// ShipToMFBill already exists
blnSTMFBFound = true;
// Update it
thisShipToMFBill.RowMod = "U";
thisShipToMFBill.PayAccount = ipPayAccount;
thisShipToMFBill.PayBTAddress1 = ipPayBTAddress1;
thisShipToMFBill.PayBTAddress2 = ipPayBTAddress2;
thisShipToMFBill.PayBTAddress3 = ipPayBTAddress3;
thisShipToMFBill.PayBTCity = ipPayBTCity;
thisShipToMFBill.PayBTState = ipPayBTState;
thisShipToMFBill.PayBTZip = ipPayBTZip;
thisShipToMFBill.PayBTCountryNum = ipPayBTCountryNum;
thisShipToMFBill.PayBTPhone = ipPayBTPhone;
And here is the full error message: (thanks to @klincecum for the event log dashboard!)
Ice.Common.EpicorServerException: BPM runtime caught an unexpected exception of 'IndexOutOfRangeException' type.
See more info in the Inner Exception section of Exception Details.
---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Epicor.Customization.Bpm.BO.UpdatePreProcessingDirective_SaveBillingAddrToShipTo_9887B4D440324B0B921D9DDA3F4602F6.A002_InvokeEpicorFunctionAction2()
at Epicor.Customization.Bpm.BO.UpdatePreProcessingDirective_SaveBillingAddrToShipTo_9887B4D440324B0B921D9DDA3F4602F6.ExecuteCore(Int32 step)
at Epicor.Customization.Bpm.DirectiveBase`2.Execute() in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 333
at Epicor.Customization.Bpm.DirectiveBase`2.Execute(TParam parameters) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 222
--- End of inner exception stack trace ---
at Epicor.Customization.Bpm.DirectiveBase`2.Execute(TParam parameters) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 222
at Epicor.Customization.Bpm.MethodCustomizationBase2`2.<>c__DisplayClass11_0.<RunDirectives>b__3(MethodDirectiveBase`2 dir) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Internal\Lib\Epicor.Customization.Bpm\MethodCustomizationBase2.cs:line 135
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Epicor.Customization.Bpm.MethodCustomizationBase2`2.RunDirectives(TParam parameters) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Internal\Lib\Epicor.Customization.Bpm\MethodCustomizationBase2.cs:line 0
at Epicor.Customization.Bpm.CustomizationBase2`2.Execute(TParam parameters) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Internal\Lib\Epicor.Customization.Bpm\CustomizationBase2.cs:line 98
at Epicor.Customization.Bpm.BO.SalesOrderSvcCustomization.Update(SalesOrderTableset& ds)
at Erp.Services.BO.SalesOrderSvcFacade.Update(SalesOrderTableset& ds) in C:\_releases\ERP\ERP11.2.400.6\Source\Server\Services\BO\SalesOrder\SalesOrderSvcFacade.cs:line 11609
at Erp.Services.BO.SalesOrderSvc.MasterUpdate(Boolean lCheckForOrderChangedMsg, Boolean lcheckForResponse, String cTableName, Int32 iCustNum, Int32 iOrderNum, Boolean lweLicensed, Boolean& lContinue, String& cResponseMsg, String& cCreditShipAction, String& cDisplayMsg, String& cCompliantMsg, String& cResponseMsgOrdRel, String& cAgingMessage, String& cShipByDateMessage, String& cNeedByDateMessage, SalesOrderTableset& ds) in C:\_releases\ERP\ERP11.2.400.6\Source\Server\Services\BO\SalesOrder\SalesOrder.cs:line 20029
at Erp.Services.BO.SalesOrderSvcFacade.MasterUpdate(Boolean lCheckForOrderChangedMsg, Boolean lcheckForResponse, String cTableName, Int32 iCustNum, Int32 iOrderNum, Boolean lweLicensed, Boolean& lContinue, String& cResponseMsg, String& cCreditShipAction, String& cDisplayMsg, String& cCompliantMsg, String& cResponseMsgOrdRel, String& cAgingMessage, String& cShipByDateMessage, String& cNeedByDateMessage, SalesOrderTableset& ds) in C:\_releases\ERP\ERP11.2.400.6\Source\Server\Services\BO\SalesOrder\SalesOrderSvcFacade.cs:line 6792 at Ice.Hosting.RestApi.OperationInvokeHelper.CallInvoker(Type svcType, MethodInfo mi, Object[] inputs, Boolean isRoot, IceDataContext dataContext) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Framework\Epicor.Ice\Hosting\RestApi\OperationInvokeHelper.cs:line 403
at Ice.Hosting.RestApi.OperationInvokeHelper.MakeServiceCall(IceDataContext dataContext, Type svcType, MethodInfo mi, Object[] parameters) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Framework\Epicor.Ice\Hosting\RestApi\OperationInvokeHelper.cs:line 356
at Ice.Hosting.RestApi.OperationInvokeHelper.CallCustomMethod(String serviceName, MethodInfo mi, Object[] paramList) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Framework\Epicor.Ice\Hosting\RestApi\OperationInvokeHelper.cs:line 306
at Epicor.RESTApi.DataSources.CustomMethodCaller.CallMethodWithDynamicData(String serviceId, String methodName, IInputParamResolver inputResolver, Action`1 headersPublisher, Action`1 verifyMethod) in C:\_releases\ICE\ICE4.2.400.0FW\Source\Server\Framework\Epicor.RESTApi.Common\DataSources\Main\CustomMethodCaller.cs:line 74
at Ice.Hosting.AspNetCore.Controllers.ServiceMethodCallControllerBase.HandleServiceMethodCall(String serviceId, String methodName, IInputParamResolver inputResolver, Action`1 verifyMethod) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Controllers\ServiceMethodCallControllerBase.cs:line 62
at Epicor.OData.V3.Controllers.CustomActionController.HandleCustomMethodCall(IInputParamResolver inputResolver, Action`1 verifyMethod) in C:\_releases\ICE\ICE4.2.400.0FW\Source\Server\Hosting\AspNetCore\RestApi\Epicor.OData.AspNetCore.V3\Controllers\CustomActionController.cs:line 53
at lambda_method453(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Ice.Hosting.AspNetCore.Middleware.DynamicAssemblyPartMiddleware.Invoke(HttpContext context, CurrentCallInformationService currentCallInformation, ControllerLoader controllerLoader) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\DynamicAssemblyPartMiddleware.cs:line 33
at Ice.Hosting.AspNetCore.ETags.ETagMiddleware.Invoke(HttpContext httpContext) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\ETags\ETagMiddleware.cs:line 110
at Ice.Hosting.AspNetCore.ETags.ETagMiddleware.Invoke(HttpContext httpContext) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\ETags\ETagMiddleware.cs:line 110
at Ice.Hosting.AspNetCore.Middleware.DecompressRequestMiddleware.Invoke(HttpContext context) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\DecompressRequestMiddleware.cs:line 42
at Ice.Hosting.AspNetCore.Middleware.AuthenticationMiddleware.InvokeAsync(HttpContext httpContext, CurrentCallInformationService callInformation) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\AuthenticationMiddleware.cs:line 83
at Ice.Hosting.AspNetCore.Middleware.CallHeaderMiddleware.InvokeAsync(HttpContext httpContext) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\CallHeaderMiddleware.cs:line 52
at Ice.Hosting.AspNetCore.Middleware.OperationDisposerMiddleware.InvokeAsync(HttpContext httpContext) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\OperationDisposerMiddleware.cs:line 34
at Epicor.RESTApi.Middleware.ApiKeyEnforcerMiddleware.Invoke(HttpContext context) in C:\_releases\ICE\ICE4.2.400.6\Source\Server\Hosting\AspNetCore\Ice.Hosting.AspNetCore\Middleware\ApiKeyEnforcerMiddleware.cs:line 79
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
CorrelationId: 0414c495-1195-4de7-9de3-08ac02d94ab0
I’m not directly accessing any index of any set - which is why I’m wondering if I’ve broken something else in the Epicor call sequence…