I’m having a little trouble adding a new row inside of a BPM to UD05.
I created a “seed” record in the UD05 table with Key1 = 1. What I am trying to do is increment Key1 every time a new record is added to this table via this BPM. Here is my code:
//Write new record in UD05
using(var UD05Svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD05SvcContract>())
{
//grab latest record in UD05
var existingRecs = Db.UD05.Where(r=>r.Company == "JRF").LastOrDefault();
var lastKey = Convert.ToInt32(existingRecs.Key1);
var newKey = lastKey++;
//get new row
var ds = new Ice.Tablesets.UD05Tableset();
UD05Svc.GetaNewUD05(ref ds);
//modify ds
var newUD05Row = ds.UD05.FirstOrDefault();
newUD05Row.Company = "JRF";
newUD05Row.Key1 = (string)newKey.ToString();
newUD05Row.Key2 = "update_shipping";
newUD05Row.Key3 = "";
newUD05Row.Key4 = "";
newUD05Row.Key5 = "";
newUD05Row.Date01 = DateTime.Now;
newUD05Row.Character01 = json;
//update
UD05Svc.Update(ref ds);
}
When I run the code, I get this error:
Server Side Exception
BPM runtime caught an unexpected exception of 'NotSupportedException' 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 'NotSupportedException' type.
See more info in the Inner Exception section of Exception Details.
Program: EntityFramework.dll
Method: Translate
Original Exception Type: NotSupportedException
Framework Method: A003_CustomCodeAction
Framework Line Number: 0
Framework Column Number: 0
Framework Source: A003_CustomCodeAction at offset 538 in file:line:column <filename unknown>:0:0
Server Trace Stack: at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.DefaultTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Epicor.Customization.Bpm.DB45D7D135CDC4463D832D57762D519A76.PostTranDirective_UpdateTracking_DropShipHead_67848129875E4559885D630E0F86D077.A003_CustomCodeAction()
at Epicor.Customization.Bpm.DB45D7D135CDC4463D832D57762D519A76.PostTranDirective_UpdateTracking_DropShipHead_67848129875E4559885D630E0F86D077.ExecuteCore()
at Epicor.Customization.Bpm.DirectiveBase`3.Execute(TParam parameters) in C:\_Releases\ICE\RL3.2.200.0\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 147
Client Stack Trace
==================
at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
at Erp.Proxy.BO.DropShipImpl.Update(DropShipDataSet ds)
at Erp.Adapters.DropShipAdapter.OnUpdate()
at Ice.Lib.Framework.EpiBaseAdapter.Update()
at Erp.UI.App.DropShipmentEntry.Transaction.Update()
Inner Exception
===============
LINQ to Entities does not recognize the method 'Ice.Tables.UD05 LastOrDefault[UD05](System.Linq.IQueryable`1[Ice.Tables.UD05])' method, and this method cannot be translated into a store expression.
Is there something else I should be thinking of to grab the last row in the table and then increment it?