How to do it...

  1. Open the alExtensibleAppProject folder in Visual Studio Code.
  2. In Explorer, select Copy Transaction Dialog.al, and in the Editor, add the following new function:
local procedure SetFromRecordVariant(var FromRecordVariant: Variant)
var
FromTransactionEntry: Record "Transaction Entry";
FromPostedTransactionEntry: Record "Posted Transaction Entry";
begin
case FromType of
FromType::Transaction:
begin
FromTransactionEntry.Get(FromTransactionEntryNo);
FromRecordVariant := FromTransactionEntry;
end;
FromType::"Posted Transaction":
begin
FromPostedTransactionEntry.Get(FromTransactionEntryNo);
FromRecordVariant := FromPostedTransactionEntry;
end;
end;
end;
  1. Update the GetCopyTransactionParameters() function with the following:
    1. Call the new SetFromRecordVariant() function.
    2. Replace the FromSourceType and FromSourceNo parameters with FromRecordVariant.

Your function should look like this:

procedure GetCopyTransactionParameters(var FromRecordVariant: Variant; var ClearNewTransactionNo: Boolean; var GetNewUnitCost: Boolean)
begin
SetFromRecordVariant(FromRecordVariant);
ClearNewTransactionNo := ResetNewTransactionNo;
GetNewUnitCost := GetUpdatedUnitCost;
end;
  1. In Explorer, select Copy Transaction.al and in the Editor, delete the following four functions:
    • CopyTransaction()
    • DoCopyTransaction()
    • CopyFromTransaction()
    • CopyFromPostedTransaction()

Yeah, I know you have an empty codeunit right now. We'll create a new and improved version of it!

  1. Add the CopyTransaction() function:
procedure CopyTransaction()
var
CopyTransactionDialog: Page "Copy Transaction Dialog";
ClearNewTransactionNo: Boolean;
GetNewUnitCost: Boolean;
FromRecordVariant: Variant;
begin
if CopyTransactionDialog.RunModal() = Action::OK then begin
CopyTransactionDialog.GetCopyTransactionParameters(FromRecordVariant, ClearNewTransactionNo, GetNewUnitCost);
DoCopyTransaction(FromRecordVariant, ClearNewTransactionNo, GetNewUnitCost);
end;
end;
  1. Add the DoCopyTransaction() function:
local procedure DoCopyTransaction(var FromRecordVariant: Variant; var ClearNewTransactionNo: Boolean; var GetNewUnitCost: Boolean)
var
FromRecordRef: RecordRef;
DataTypeMgmt: Codeunit "Data Type Management";
begin
DataTypeMgmt.GetRecordRef(FromRecordVariant, FromRecordRef);
CopyFromSourceRecord(FromRecordRef, ClearNewTransactionNo, GetNewUnitCost);
end;
  1. Add the CopyFromSourceRecord() function:
local procedure CopyFromSourceRecord(var FromRecordRef: RecordRef; var ClearNewTransactionNo: Boolean; var GetNewUnitCost: Boolean)
var
FromTransactionEntry: Record "Transaction Entry";
FromPostedTransactionEntry: Record "Posted Transaction Entry";
NewTransaction: Record "Transaction Entry";
begin
NewTransaction.Init();
case FromRecordRef.Number() of
Database::"Transaction Entry":
begin
FromRecordRef.SetTable(FromTransactionEntry);
NewTransaction.TransferFields(FromTransactionEntry, false);
end;
Database::"Posted Transaction Entry":
begin
FromRecordRef.SetTable(FromPostedTransactionEntry);
NewTransaction.TransferFields(FromPostedTransactionEntry, false);
end;
end;
if ClearNewTransactionNo then
NewTransaction."Transaction No." := '';
if GetNewUnitCost then
NewTransaction.GetLastDirectUnitCost();
NewTransaction.Status := NewTransaction.Status::New;
NewTransaction.Insert(true);
end;

You're done!

You can now deploy your application if you want to try it out. The CopyTransaction() function should work just as it did previously in step 5, only now, we have a single set of code to maintain.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.239.77