2

How to create a copy of a DAC (i.e. cloning it) in Acumatica Framework. I can of course create a new instance and set all the value individually but is there a method which does this for you?

I found the following method

PXCache<...>.CreateCopy(sourceRule);

However, this seems to copy everything, including the ID, CreatedBy etc. I would need a new DAC, with all relevant fields copied. How to do this please?

Joseph Caruana
  • 2,241
  • 3
  • 31
  • 48
  • 1
    After researching PXCache class I can say that Acumatica's PXCache.CreateCopy and PXCache.RestoreCopy are copying all the fields that DACs have. So you probably will have to write the Copy function by yourself. – Samvel Petrosov Jul 03 '17 at 09:36
  • I think I managed to get it working by using CreateCopy and then just setting the ID to null – Joseph Caruana Jul 03 '17 at 11:36

1 Answers1

2

You can use PXCache CreateCopy to perform the copy like you mentioned, then null/change the keys before inserting the new copy into the cache.

Here is an example that will copy a sales line as a new line on a sale order extension:

var soLine = PXCache<SOLine>.CreateCopy(Base.Transactions.Current);
// Null the keys of SOLine
soLine.OrderType = null;
soLine.OrderNbr = null;
soLine.LineNbr = null;
Base.Transactions.Insert(soLine);
Brendan
  • 5,428
  • 2
  • 17
  • 33