Saturday, 21 December 2013

Copying a record in ax 2012

static void MainAccountCopy(Args _args)
{
MainAccount mainAccount1;
MainAccount mainAccount2;
mainAccount1 = MainAccount::findByMainAccountId('211100');
ttsBegin;
mainAccount2.data(mainAccount1);
mainAccount2.MainAccountId = '211101';
if (!mainAccount2.validateWrite())
{
throw Exception::Error;
}
mainAccount2.insert();
ttsCommit;
}

static void MainAccountCopy(Args _args)
{
MainAccount mainAccount1;
MainAccount mainAccount2;
mainAccount1 = MainAccount::findByMainAccountId('211100');
ttsBegin;
buf2Buf(mainAccount1, mainAccount2);
mainAccount2.MainAccountId = '211101';
if (!mainAccount2.validateWrite())
{
throw Exception::Error;
}
mainAccount2.insert();
ttsCommit;
}

static void buf2Buf(Common _from, Common _to)
{
     DictTable dictTable = new DictTable(_from.TableId);
      FieldId fieldId = dictTable.fieldNext(0);
     while (fieldId && ! isSysId(fieldId))
    {
          _to.(fieldId) = _from.(fieldId);
          fieldId = dictTable.fieldNext(fieldId);
      }
}

No comments:

Post a Comment