Error when checking out EWB from UBAQ and data directive BPM using c# custom code for more than 1 row

Please see BPM data directive c# code below.

I have a UBAQ that updates UD10 and a fire on UD10 updated rows data directive BPM that calls BO’s to check out revisions. When I change 1 row with 1 part and revision the BAQ works without an error. When I change 2 or more rows with different parts and revisions I get the error below.

Please help!
Thanks,
Richard

C# code:
using (var txScope = IceContext.CreateDefaultTransactionScope())
{
Erp.Contracts.EngWorkBenchSvcContract engWorkBench = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.EngWorkBenchSvcContract>(this.Db, true);
bool opPromptForPassword = false;
foreach (var ttUD10_iterator in ttUD10)
{
Ice.Tables.UD13 UD13;
var ttud10_Row = ttUD10_iterator;
string ipGroupID = this.Session.UserID;
string ipPartNum = ttud10_Row.Key2;
string ipRevisionNum = ttud10_Row.Key3;
string ipAltMethod = ttud10_Row.Key4;
DateTime? ipAsOfDate = DateTime.Today;
bool ipCompleteTree = false;
bool ipValidPassword = false;
bool ipReturn = true;
bool ipGetDatasetForTree = true;
bool ipUseMethodForParts = false;
string ipAuditText = “Dashboard Change Part Std”;
string opMessage = “”;
string opResultString = “”;
string opCheckedOutRevisionNum = “”;
string altMethodMsg = “”;
bool altMethodFlg = false;
engWorkBench.PromptForPassword(out opPromptForPassword);
ipValidPassword = true;
ipReturn = false;
engWorkBench.CheckOut(ipGroupID,ipPartNum,ipRevisionNum,ipAltMethod,ipAsOfDate,ipCompleteTree,ipValidPassword,ipReturn,ipGetDatasetForTree,ipUseMethodForParts,out opCheckedOutRevisionNum,out altMethodMsg,out altMethodFlg);
}

}
txScope.Complete();
}

Error:
Server Side Exception

BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
See more info in the Inner Exception section of Exception Details.

Exception caught in: Epicor.ServiceModel

Error Detail

Description: BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
See more info in the Inner Exception section of Exception Details.
Program: Epicor.System.dll
Method: GetObjectSetCache
Line Number: 354
Column Number: 13
Original Exception Type: NullReferenceException
Server Trace Stack: at Epicor.Data.DBExpressionCompiler.GetObjectSetCache[TResult](EpiDataContext dataContext, Cache cacheSetting) in C:_Releases\ICE\ICE3.2.100.43\Source\Framework\Epicor.System\Data\DBExpressionCompiler.cs:line 354
at Epicor.Data.DBExpressionCompiler.InvokeSingle[TContext,TQuery,TResult](Expression expression, Cache currentCacheSetting, Boolean cacheQuery, TContext dataContext, Func2 getDataCacheKey, Func2 compileQuery, Func3 executeQuery) in C:\_Releases\ICE\ICE3.2.100.43\Source\Framework\Epicor.System\Data\DBExpressionCompiler.cs:line 256 at Epicor.Data.DBExpressionCompiler.<>c__DisplayClass33_03.b__0(TContext context, TArg1 arg1) in C:_Releases\ICE\ICE3.2.100.43\Source\Framework\Epicor.System\Data\DBExpressionCompiler.Generated.cs:line 1089
at Erp.Internal.BM.BMM10_GD.CheckOutRev(String cPartNum, String cRevisionNum, String cAltMethod, String cGroupID) in C:_Releases\ERP\UD10.2.100.43\Source\Server\Internal\BM\EngWBLib\BMM10-GD.i.cs:line 5936
at Erp.Services.BO.EngWorkBenchSvc.checkOutRevision(PartRev bPartRev, Boolean& altmethflg) in C:_Releases\ERP\UD10.2.100.43\Source\Server\Services\BO\EngWorkBench\EngWorkBench.cs:line 8702
at Erp.Services.BO.EngWorkBenchSvc.CheckOut(String ipGroupID, String ipPartNum, String ipRevisionNum, String ipAltMethod, Nullable1 ipAsOfDate, Boolean ipCompleteTree, Boolean ipValidPassword, Boolean ipReturn, Boolean ipGetDatasetForTree, Boolean ipUseMethodForParts, String& opCheckedOutRevisionNum, String& altMethodMsg, Boolean& altMethodFlg) in C:\_Releases\ERP\UD10.2.100.43\Source\Server\Services\BO\EngWorkBench\EngWorkBench.cs:line 8658 at Epicor.Customization.Bpm.DB85A7EA6A282A41F7B90B1AC22CD8D207.PostTranDirective_partstdupddash_DEF18B0BAF2847D6BCDA802D24073261.A001_CustomCodeAction() at Epicor.Customization.Bpm.DB85A7EA6A282A41F7B90B1AC22CD8D207.PostTranDirective_partstdupddash_DEF18B0BAF2847D6BCDA802D24073261.ExecuteCore() at Epicor.Customization.Bpm.DirectiveBase3.Execute(TParam parameters) in C:_Releases\ICE\ICE3.2.100.43\Source\Server\Internal\Lib\Epicor.Customization.BPM\DirectiveBase.Generic.cs:line 131

Client Stack Trace

at Epicor.ServiceModel.Channels.ImplBase1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets) at Ice.Proxy.BO.DynamicQueryImpl.Update(DynamicQueryDataSet queryDS, DataSet queryResultDataset) at Ice.Adapters.DynamicQueryAdapter.<>c__DisplayClass27_0.<Update>b__0(DataSet datasetToSend) at Ice.Adapters.DynamicQueryAdapter.ProcessUbaqMethod(String methodName, DataSet updatedDS, Func2 methodExecutor, Boolean refreshQueryResultsDataset)
at Ice.Adapters.DynamicQueryAdapter.Update(DynamicQueryDataSet queryDS, DataSet updatedDS, Boolean refreshQueryResultsDataset)
at Ice.UI.App.BAQDesignerEntry.BAQTransaction.b__387_0(Int32& rowReturned)
at Ice.UI.App.BAQDesignerEntry.Forms.BAQDiagramForm.ShowQueryResults(DataSet dsResults, getQueryResult getResults, ReportAdditionalInfo additionalInfo)
at Ice.UI.App.BAQDesignerEntry.BAQTransaction.CallUpdate()

Inner Exception

Object reference not set to an instance of an object.

I figured it out. I moved the data directive to the ubaq update post-processing BPM directive and it works great with multiple rows!