Copy one tableset to another

,

DataSet.Copy?

DataSet.Copy Method (System.Data) | Microsoft Learn

That was my first thought but he did technically ask for Tableset… :smiley:

Update by query and then fill in the mappings??

Or am I missing what you are trying to do.

Excuse my ignorance… but is a dataset and a tableset the same thing? I know in Epicor I’m calling it a tableset but it’s called a ds in the method directive… so… yeah I don’t really know what the difference is if there is one.

They are different, but for most uses for us, they are the same.

Convert Erp.Tablesets to System.Data.DataSet - ERP 10 - Epicor User Help Forum (epiusers.help)

1 Like

You know, I tried that but I overlooked that my tables were in there. I just saw the tt tables and the ERP tables and I just assumed that was all I had. But yeah I think this would work.

If you have a dataset that needs to be returned from a bpm, and not a tableset you can use
this.dsHolder.Attach(ds); to attach your dataset instead.

What exactly are you working with?

I used that yesterday :slight_smile: Thanks @Olga lol

1 Like

I am working with UD100 and UD100A. When a record is updated in UD100A, I am checking all the child rows in UD100A and then updating a field in UD100 (a status). Only the rows I’m modifying show up in the ttUD100A in the ds in the method directive. So I am instantiating my own ds and doing a GetByID to pull in all the child rows. Then I can loop through them and check what I need to check to set my status on UD100. That part works fine. But my next step is that if the status is changed to “CLOSED”, then I need to fire off another BPM that does some stuff on the Sales Order BO and it involves the data in my ds for UD100A. However, I can’t pass that from one BPM to the next. So I figured if I could dump that back into the default ds, then I could do what I need to do in the next BPM because all my rows would be in there. I’m under the impression that as long as I don’t set the RowMod to U that the Update method will not do anything to the unchanged rows.

Is this in your 10 environment or 11 ?

10

Are all the records you need in the new tableset you made, and in the proper state?
If so, dsHolder.Attach is what you want.

If you need just to copy some rows from the one you made to the existing, you’ll have to do something different.

Something like this

  UD100Tableset yourTS = new UD100Tableset();
  
  var rowsToCopy = yourTS.UD100A.Where(x => x.Character01 == "Your Criteria Here")
                             .Select(x => x)
                             .ToList();

  
  ds.UD100A.AddRange(rowsToCopy);   //ttUD100A in yours ?     

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