How to do it...

  1. Open the alExtensibleAppProject folder in Visual Studio Code.
  2. In Explorer, create a new file named Copy Transaction Argument.al and create the following table object:
table 50003 "Copy Transaction Argument"
{
fields
{
field(1; "Reset Transaction No."; Boolean)
{
}
field(2; "Get Updated Unit Cost"; Boolean)
{
}
}
}
There is no primary key defined as we will never physically insert records into this table.
  1. In Explorer, select Copy Transaction Dialog.al and in the Editor, add the following new function:
local procedure SetArgumentTable(var TempCopyTransactionArgument: Record "Copy Transaction Argument" temporary)
begin
TempCopyTransactionArgument."Get Updated Unit
Cost" := GetUpdatedUnitCost;
TempCopyTransactionArgument."Reset Transaction
No." := ResetNewTransactionNo;
end;
  1. Replace the existing GetCopyTransactionParameters() function with the following one:
procedure GetCopyTransactionParameters(var FromRecordVariant: Variant; var TempCopyTransactionArgument: Record "Copy Transaction Argument" temporary)
begin
SetFromRecordVariant(FromRecordVariant);
SetArgumentTable(TempCopyTransactionArgument);
end;
  1. Replace the existing CopyTransaction() function with the following one:
procedure CopyTransaction()
var
CopyTransactionDialog: Page "Copy Transaction Dialog";
FromRecordVariant: Variant;
TempCopyTransactionArgument: Record
"Copy Transaction Argument" temporary;
begin
if CopyTransactionDialog.RunModal() = Action::OK then begin
CopyTransactionDialog.GetCopyTransactionParameters(
FromRecordVariant, TempCopyTransactionArgument);
DoCopyTransaction(FromRecordVariant,
TempCopyTransactionArgument);
end;
end;
  1. Replace the existing DoCopyTransaction() function with the following one:
local procedure DoCopyTransaction(var FromRecordVariant: Variant; var TempCopyTransactionArgument: Record "Copy Transaction Argument" temporary)
var
FromRecordRef: RecordRef;
DataTypeMgmt: Codeunit "Data Type Management";
begin
DataTypeMgmt.GetRecordRef(FromRecordVariant, FromRecordRef);
CopyFromSourceRecord(FromRecordRef,
TempCopyTransactionArgument);
end;
  1. Replace the CopyFromSourceRecord() function with the following one:
local procedure CopyFromSourceRecord(var FromRecordRef: RecordRef; var TempCopyTransactionArgument: Record "Copy Transaction Argument" temporary)
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 TempCopyTransactionArgument."Reset Transaction No." then
NewTransaction."Transaction No." := '';
if TempCopyTransactionArgument."Get Updated Unit Cost" then
NewTransaction.GetLastDirectUnitCost();
NewTransaction.Status := NewTransaction.Status::New;
OnBeforeInsertNewTransactionEntry(
NewTransaction, TempCopyTransactionArgument);
NewTransaction.Insert(true);
end;
  1. Now, create a new event:
[IntegrationEvent(false, false)]
local procedure OnBeforeInsertNewTransactionEntry(var NewTransaction: Record "Transaction Entry"; var TempCopyTransactionArgument: Record "Copy Transaction Argument" temporary)
begin
end;

This event will let other developers subscribe and process any new arguments that they add to the Copy Transaction Argument table.

Now we've created a set of functions that we can pass parameters through and we'll never need to update the signatures to handle any updates to the parameters.

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

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