Help with inserting new row into UD child table in a BAQ

We are currently doing our uplift from E9 to E10. I have used the migration tool to convert my ABL to C#. I already know that it is not perfect and should not be your production code. I am learning C# but can be considered very green.
Anyhow, I have a BAQ that utilizes UD102 and writes to UD102A for logging purposes. Works fantastic in 9. I am unsure how to insert a new row into the UD102A table. Here is the code the migration tool converted my ABL to. Can anyone help?

    /* Write proposed changes to UD102A */
bool wasCreated = false;
decimal cRecordNum = 0;
decimal cLogNum = 0;
string cText = string.Empty;
decimal theKey = 0;
Ice.Tables.UD102 UD102;
Erp.Tables.Company Company;
Ice.Tables.UD102A UD102A;
wasCreated = false;
foreach (var ttResults_xRow in ttResults)
{
    var ttResultsRow = ttResults_xRow;
    var PONum = ttResultsRow.POHeader_PONum.ToString();
    var POLine = ttResultsRow.PODetail_POLine.ToString();
    
    UD102 = (from UD102_Row in Db.UD102
             where UD102_Row.Key2 == PONum && UD102_Row.Key3 == POLine
             select UD102_Row).FirstOrDefault();
    if (UD102 == null)
    {
        Company = (from Company_Row in Db.Company
                   where Company_Row.Company1 == Session.CompanyID
                   select Company_Row).FirstOrDefault();
        if (Company != null)
        {
            cRecordNum = Company.Number11 + 1;
            ttResultsRow.UD102_Company = Session.CompanyID;
            ttResultsRow.UD102_Key1 = System.Convert.ToString(cRecordNum);
            ttResultsRow.UD102_Key2 = PONum;
            ttResultsRow.UD102_Key3 = POLine;
            ttResultsRow.UD102_Number02 = 1;
            Company.Number11 = cRecordNum;
            /* Log changes in UD102A */
            cLogNum = Company.Number12 + 1;
            theKey = cRecordNum + 1;
            
            UD102A = new Ice.Tables.UD102A();
            Db.UD102A.Insert(UD102A);
            UD102A.Company = Session.CompanyID;
            UD102A.Key1 = System.Convert.ToString(cLogNum);
            UD102A.Key2 = ttResultsRow.UD102_Key3;
            UD102A.ChildKey1 = ttResultsRow.UD102_Key1;
            UD102A.Date01 = DateTime.Now;
            UD102A.Date02 = ttResultsRow.UD102_Date02;
            UD102A.Number01 = ttResultsRow.UD102_Number01;
            UD102A.Character01 = ttResultsRow.UD102_Character01;
            UD102A.ShortChar01 = Session.UserID;
            UD102A.Number02 = ttResultsRow.POHeader_PONum;
            Company.Number12 = cLogNum;
            wasCreated = true;
        }
    }
}

Do you have the Epicor ERP C# Programming Guide (conversion from ABL)? You can find it on Epicweb. It has examples about converting abl to c#. One particular example is how to write to a UD table.

I don’t but I need it obviously. Let me see if I can get it. Thanks

Youll want to use the business object to insert the record.

var UD12svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD12SvcContract>(Db);
var ds = new UD12Tableset();
        UD12svc.GetaNewUD12(ref ds);
        ds.UD12[0].Key1 = iIp.ToUpper();
        ds.UD12[0].Key2 = DateTime.Today.ToShortDateString();
        ds.UD12[0].Key3 = string.Empty;
        ds.UD12[0].Key4 = "IP_BLOCK";
        ds.UD12[0].Number01 =num01;
        UD12svc.Update(ref ds);

Jose,
I get “The type or namespace name ‘UD102ASvcContract’ does not exist in the namespace ‘Ice.Contracts’ (are you missing an assembly reference?)”

Thanks,
Chris

You need to bring in the UD102 assembly reference.

Like this?
image

Still getting the error

1 Like

I’m so close to figuring it out here. I now have the following just using strings for testing for now.
var UD102svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD102SvcContract>(Db);
var ds = new UD102Tableset();
UD102svc.GetaNewUD102A(ref ds);
ds.UD102A[0].Company = “GCB”;
ds.UD102A[0].Key1 = “KEY1”;
ds.UD102A[0].Key2 = “KEY2”;
ds.UD102A[0].Key3 = “KEY3”;
ds.UD102A[0].Key4 = “KEY4”;
ds.UD102A[0].Key5 = “KEY5”;
ds.UD102A[0].ChildKey1 = “CHILDKEY1”;
ds.UD102A[0].ChildKey2 = “CHILDKEY2”;
ds.UD102A[0].ChildKey3 = “CHILDKEY3”;
ds.UD102A[0].ChildKey4 = “CHILDKEY4”;
ds.UD102A[0].ChildKey5 = “CHILDKEY5”;
UD102svc.Update(ref ds);

However, syntax error says: CS7036 There is no argument given that corresponds to the required formal parameter ‘ParentKey1’ of ‘UD102SvcContract.GetaNewUD102A(ref UD102Tableset, string, string, string, string, string)’

Before you add the UD102A, you have to have the UD102 record there first.

Mark,

I’m not understanding. This is an updatable BAQ. I am setting it in the temp table just prior. Sorry, this is very new to me.

cRecordNum = Company.Number11 + 1;
            ttResultsRow.UD102_Company = Session.CompanyID;
            ttResultsRow.UD102_Key1 = System.Convert.ToString(cRecordNum);
            ttResultsRow.UD102_Key2 = PONum;
            ttResultsRow.UD102_Key3 = POLine;
            ttResultsRow.UD102_Number02 = 1;
            Company.Number11 = cRecordNum;
            
            /* Log changes in UD102A */
            cLogNum = Company.Number12 + 1;
            theKey = cRecordNum + 1;
            
              var UD102svc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD102SvcContract>(Db);          
              var ds = new UD102Tableset();
              UD102svc.GetaNewUD102A(ref ds);
//Do I do something like this here? ds.UD102[0].
              ds.UD102A[0].Company = "GCB";
              ds.UD102A[0].RowMod = "A";
              ds.UD102A[0].Key1 = Convert.ToString(cLogNum);
              ds.UD102A[0].Key2 = ttResultsRow.UD102_Key3;
              ds.UD102A[0].Date01 = DateTime.Now;
              ds.UD102A[0].Date02 = ttResultsRow.UD102_Date02;
              ds.UD102A[0].ChildKey1 = ttResultsRow.UD102_Key1;
              ds.UD102A[0].Number01 = ttResultsRow.UD102_Number01;
              ds.UD102A[0].Character01 = ttResultsRow.UD102_Character01;
              ds.UD102A[0].ShortChar01 = Session.UserID;
              ds.UD102A[0].Number02 = ttResultsRow.POHeader_PONum;
              UD102svc.Update(ref ds);

Think of it like a Sales Order or Purchase Order. Your key field in the header (Sales Order Number) must exist before your details can be added. It’s the same for the UD##A tables. You must have record UD102 filled with Key1-Key5 (even if some are blank). Your UD102A Key1-Key5 MUST be identical to the UD102 Key1-Key5 or you’ll get this message.

ttResultsRow.UD102_Company = Session.CompanyID;
ttResultsRow.UD102_Key1 = System.Convert.ToString(cRecordNum);
ttResultsRow.UD102_Key2 = PONum;
ttResultsRow.UD102_Key3 = POLine;

must be the same in the UD102A records:

ds.UD102A[0].Company = “GCB”;
ds.UD102A[0].RowMod = “A”;
ds.UD102A[0].Key1 = System.Convert.ToString(cRecordNum);
ds.UD102A[0].Key2 = ttResultsRow.UD102_Key2 = PONum;
ds.UD102A[0].Key2 = ttResultsRow.UD102_Key2 = POLine;

Then you add your child keys and extra fields from there.

Ahhhh now I get it. Thanks for the explanation. So I should be creating UD102A in post… Thank you!

Still a no go. Same error. It seems that UD102Asvc.GetaNewUD102A(ref ds); is requiring a parameter or parameters according to the error?

There is no argument given that corresponds to the required formal parameter ‘ParentKey1’ of ‘UD102SvcContract.GetaNewUD102A(ref UD102Tableset, string, string, string, string, string)’

I see you assigning the ttResultsRow but are you assigning the UD102 in the ds?

ds.UD102_Company = Session.CompanyID;
ds.UD102_Key1 = System.Convert.ToString(cRecordNum); 
ds.UD102_Key2 = PONum; ds.UD102_Key3 = POLine;

or whatever the field names are…

Yes I am

Are you hard-coding the company? Are you sure the Session.CompanyID is also “GCB”?

Tried both ways. No difference.

The error seems to be looking for a different signature than you’re passing in:

‘UD102SvcContract.GetaNewUD102A(ref UD102Tableset, string, string, string, string, string)’

Try passing in your parent keys in your GetaNewUD102A.

Mark,

That did it. Although now I get a server error. Bout done with this.
Server Side Exception

A server error occurred. Review the server event logs for details.

Exception caught in: Epicor.ServiceModel

Error Detail

Description: A server error occurred. Review the server event logs for details.
Program: Epicor.System.dll
Method: ProvideFault
Line Number: 32
Column Number: 13
Server Trace Stack: at Epicor.Hosting.Wcf.ErrorHandler.ProvideFault(Exception error, MessageVersion version, Message& fault) in C:_Releases\ICE\ICE3.2.400.0\Source\Framework\Epicor.System\Hosting\Wcf\ErrorHandler.cs:line 32
at System.ServiceModel.Dispatcher.ErrorBehavior.ProvideFault(Exception e, FaultConverter faultConverter, ErrorHandlerFaultInfo& faultInfo)
at System.ServiceModel.Dispatcher.ErrorBehavior.ProvideMessageFaultCore(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage8(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.ProcessError(Exception e)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
at System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.SecurityChannelListener1.ReceiveItemAndVerifySecurityAsyncResult2.InnerTryReceiveCompletedCallback(IAsyncResult result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at System.Runtime.InputQueue1.Dispatch()
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

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__380_0(Int32& rowReturned)
at Ice.UI.App.BAQDesignerEntry.Forms.BAQDiagramForm.ShowQueryResults(DataSet dsResults, getQueryResult getResults, ReportAdditionalInfo additionalInfo)
at Ice.UI.App.BAQDesignerEntry.BAQTransaction.CallUpdate()

bool wasCreated;
decimal cRecordNum = 0;
decimal cLogNum = 0;
string cText = string.Empty;
decimal theKey = 0;
Ice.Tables.UD102 UD102;
Erp.Tables.Company Company;
Ice.Tables.UD102A UD102A;
wasCreated = false;
foreach (var ttResults_xRow in ttResults)
{
var ttResultsRow = ttResults_xRow;
var PONum = ttResultsRow.POHeader_PONum.ToString();
var POLine = ttResultsRow.PODetail_POLine.ToString();

UD102 = (from UD102_Row in Db.UD102
         where UD102_Row.Key2 == PONum && UD102_Row.Key3 == POLine
         select UD102_Row).FirstOrDefault();
if (UD102 == null && wasCreated == false)
{
    Company = (from Company_Row in Db.Company
               where Company_Row.Company1 == Session.CompanyID
               select Company_Row).FirstOrDefault();
    if (Company != null)
    {
        cRecordNum = Company.Number11 + 1;
        ttResultsRow.UD102_Company = Session.CompanyID;
        ttResultsRow.UD102_Key1 = System.Convert.ToString(cRecordNum);
        ttResultsRow.UD102_Key2 = PONum;
        ttResultsRow.UD102_Key3 = POLine;
        ttResultsRow.UD102_Key4 = "";
        ttResultsRow.UD102_Key5 = "";
        ttResultsRow.UD102_Number02 = 1;
        
          Company.Number11 = cRecordNum;
          
          /* Log changes in UD102A */
          cLogNum = Company.Number12 + 1;
          theKey = cRecordNum + 1;
        
          var UD102Asvc = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD102SvcContract>(Db);          
          var ds = new UD102Tableset();
          UD102Asvc.GetaNewUD102A(ref ds, ttResultsRow.UD102_Key1, ttResultsRow.UD102_Key2, ttResultsRow.UD102_Key3, ttResultsRow.UD102_Key4, ttResultsRow.UD102_Key5);
          ds.UD102A[0].Company = Session.CompanyID;
          ds.UD102A[0].RowMod = "A";
          ds.UD102A[0].Key1 = System.Convert.ToString(cRecordNum);
          ds.UD102A[0].Key2 = PONum;
          ds.UD102A[0].Key3 = POLine;
          ds.UD102A[0].Key4 = "";
          ds.UD102A[0].Key5 = "";
          ds.UD102A[0].Date01 = DateTime.Now;
          ds.UD102A[0].Date02 = ttResultsRow.UD102_Date02;
          ds.UD102A[0].ChildKey1 = ttResultsRow.UD102_Key1;
          ds.UD102A[0].ChildKey2 = Convert.ToString(cLogNum);
          ds.UD102A[0].ChildKey3 = PONum;
          ds.UD102A[0].ChildKey4 = POLine;
          ds.UD102A[0].ChildKey5 = "";
          ds.UD102A[0].Number01 = ttResultsRow.UD102_Number01;
          ds.UD102A[0].Character01 = ttResultsRow.UD102_Character01;
          ds.UD102A[0].ShortChar01 = Session.UserID;
          ds.UD102A[0].Number02 = ttResultsRow.POHeader_PONum;
          UD102Asvc.Update(ref ds);
          
          Company.Number12 = cLogNum;
          wasCreated = true;
    }
}

}