Copy one tableset to another

,

Where Are You Waiting GIF by This GIF Is Haunted

Haha it’s not working yet. Evidently I am breaking something when I try it but I’m not sure if it’s the way I’m doing it or what. It just breaks silently with no error… haha. Sorry to keep you in suspense.

1 Like

I am trying to use the .Add method for each row instead of the .AddRange on the collection. Do you think it makes a difference?

I wouldn’t think so.

What is it saying? (Is it still silent?)

Can we see some code?

Ok. So in the Event Viewer there is an error that has to do with the .Add method.

Server Side Error
Server Side Exception
EpicorServerException
Description: BPM runtime caught an unexpected exception of ‘ArgumentException’ type.
See more info in the Inner Exception section of Exception Details.
Program: Epicor.ServiceModel.dll
Method: Add
Line Number: 139
Column Number: 17
Original Exception Type: ArgumentException
Server Trace Stack: at Ice.IceTable1.Add(TRow row) in C:\_Releases\ICE\ICE3.2.300.40\Source\Shared\Framework\Epicor.ServiceModel\Ice\Tableset\IceTable.cs:line 139 at Epicor.Customization.Bpm.BO13DFF29326894E93A17C47147BCCA43F.UpdatePreProcessingDirective_Test_583AE911C2AE43B3869268B5CDEC53F1.A001_CustomCodeAction() at Epicor.Customization.Bpm.BO13DFF29326894E93A17C47147BCCA43F.UpdatePreProcessingDirective_Test_583AE911C2AE43B3869268B5CDEC53F1.ExecuteCore() at Epicor.Customization.Bpm.DirectiveBase3.Execute(TParam parameters) in C:_Releases\ICE\ICE3.2.300.40\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 147

Current Code:

Ice.Contracts.UD100SvcContract boUD100 = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD100SvcContract>(Db);
Ice.Tablesets.UD100Tableset dsUD100 = new Ice.Tablesets.UD100Tableset();

// ----------------------------------------------------------------
// Get the key1 from the first row in the dataset. 
// All rows in this table should be the same key1.
// We will use this key to get all records related to the key1.
// ----------------------------------------------------------------
string key1 = (from t in ttUD100A
                       where t.Key1 != ""
                       && t.RowMod == "U"
                       select t.Key1).FirstOrDefault() ?? String.Empty;

// ----------------------------------------------------------------
// Get all updated records. 
// Since this is pre-processing, none of our updated rows are
//   committed to the database yet. 
// We will loop through each row in the ds and update it based on
//   what has been updated in this transaction.
// ----------------------------------------------------------------
var updatedRows = (from t in ttUD100A
                       where t.Key1 != ""
                       && t.RowMod == "U"
                       select t).ToList();

if (!String.IsNullOrEmpty(key1))
{
// ----------------------------------------------------------------
// Fill the dataset with all records tied to this key1
// ----------------------------------------------------------------   
  dsUD100 = boUD100.GetByID(key1, "", "", "", "");
  
// ----------------------------------------------------------------
// Loop through each record in the ds.
// ----------------------------------------------------------------  
  foreach (var eachRow in (from u in dsUD100.UD100A
                           where u.Company == callContextClient.CurrentCompany
                           && u.Key1 == key1
                           select u))
  {
    
    string childKey1 = eachRow.ChildKey1;
    string childKey2 = eachRow.ChildKey2;
    string childKey3 = eachRow.ChildKey3;
    msg += "Child Keys: " + childKey1 + "-" + childKey2 + "-" + childKey3 + "\n";

// ----------------------------------------------------------------
// Check each ds record to see if it is already in the tt.
// If it is, we don't need to do anything. 
// If it's not, add it to the tt.
// ----------------------------------------------------------------      
    var isUpdated = (from u in updatedRows
                     where u.Key1 == key1
                     && u.ChildKey1 == childKey1
                     && u.ChildKey2 == childKey2
                     && u.ChildKey3 == childKey3
                     && u.RowMod == "U"
                     select u).FirstOrDefault();
    if (isUpdated != null)
    {

    }
    else
    {
      ttUD100A.Add(eachRow);
      msg += "Attempted to add a row\n";
    }
  } 
}

That row is part of this TableSet

(from u in dsUD100.UD100A
                           where u.Company == callContextClient.CurrentCompany
                           && u.Key1 == key1
                           select u)

It cannot be added to another TableSet.

You can buffercopy to a new row, or do this

(from u in dsUD100.UD100A
                           where u.Company == callContextClient.CurrentCompany
                           && u.Key1 == key1
                           select u).ToList()
1 Like

Thanks for all your help so far.
This got me to the same error. I’ll see if I can try the Buffer Copy next.

1 Like

The buffer copy seems to be the magic I was looking for.

    else
    {
      var newRecord = ttUD100A.NewRow();
      BufferCopy.Copy(eachRow, newRecord);
      ttUD100A.Add(newRecord);
      msg += "Attempted to add a row\n";
    }
1 Like

I don’t know what I was thinking there lol, yeah that would still need a copy, it’s a reference, not a
new row.

Where are you trying to do this? Is this client code in a customization or are you writing something external to consume the services with REST?

This was in a method directive on UD100.Update. The Buffer Copy thing worked for me. I should probably mark this solved.