4

I am trying to write the following statement in Acumatica using PXDatabase.Update:

UPDATE MyTable SET MyField2 = MyField1

I want to use PXDatabase.Update for an upgrade process. I have used PXDatabase.Update many times using PXDataFieldAssign and PXDataFieldRestrict and this works well. I cannot find the correct syntax to have a field set from another field in the same DAC (only specific values).

What is the correct Syntax using PXDatabase.Update?

Edit: I am open to other calls that allow for a bulk update other than PXDatabase.Update (1 update for the entire table by company).

Brendan
  • 5,428
  • 2
  • 17
  • 33

1 Answers1

2

The following should do what you're looking for.

using (PXTransactionScope ts = new PXTransactionScope())
{
    PXDatabase.Update<MyTable>(new PXDataFieldAssign<MyTable.myField2>(PXDbType.DirectExpression, "MyField1"));
    ts.Complete();
}
Philippe
  • 986
  • 1
  • 6
  • 17
  • 1
    This is exactly what i needed! thanks Philippe. I wrapped "MyField1" with the quote identifier using _upgradeGraph.SqlDialect.quoteDbIdentifier("MyField1") for peace of mind. Confirmed the resulting sql is exactly what i need. – Brendan Oct 31 '16 at 15:52
  • That's a good practice. You might want to be even safer by wrapping both the table and the column with graph.SqlDialect.quoteTableAndColumn("MyTable", "MyField1") – Philippe Oct 31 '16 at 17:28