How to do it...

  1. In Visual Studio Code, open the alExtensibleAppProject folder. In Explorer, select Transaction Entry.al and add the following field in Editor:
field(10; Status; Enum "Transaction Status")
{
}
  1. In Explorer, create a new file named Transaction Status.al, and in Editor, create a new enum object. Let's also add the New and Verified values to the enum:
enum 50000 "Transaction Status"
{
Extensible = true;

value(0; New)
{
Caption = 'New';
}
value(1; Verified)
{
Caption = 'Verified';
}
}
You can use the tenum snippet to quickly create a new enum object.
  1. Now, add the new field to the Transaction Worksheet.al file, after the Suggested Unit Price field:
field(Status; Status)
{
ApplicationArea = All;
}
  1. Let's add a check to make sure that when the transaction is posted, the Status is set to Verified.

In Explorer, select Post Transaction.al and add the check after the Suggested Unit Price check, as follows:

local procedure VerifyTransactionEntry(var TransactionEntry: Record "Transaction Entry")
begin
with TransactionEntry do begin
TestField("Transaction No.");
TestField("Item No.");
TestField(Quantity);
TestField("Unit Cost");
TestField("Suggested Unit Price");
TestField(Status, Status::Verified);
end;
OnAfterVerifyTransactionEntry(TransactionEntry);
end;

As you can see, the syntax for using an enum in code is the same as it is when using an option.

  1. And finally, add the following code to the following function to reset the Status when an existing transaction is copied to a new one:
local procedure CopyFromTransaction(var FromSourceEntryNo: Integer; var ClearNewTransactionNo: Boolean; var GetNewUnitCost: Boolean)
var
OldTransaction: Record "Transaction Entry";
NewTransaction: Record "Transaction Entry";
begin
OldTransaction.Get(FromSourceEntryNo);
NewTransaction.Init();
NewTransaction.TransferFields(OldTransaction, false);
if ClearNewTransactionNo then
NewTransaction."Transaction No." := '';
if GetNewUnitCost then
NewTransaction.GetLastDirectUnitCost();
NewTransaction.Status := NewTransaction.Status::New;
NewTransaction.Insert(true);
end;
  1. Now, use F5 to build and deploy the application in order to try it out.

Once you're logged in to the sandbox, follow these steps:

    1. Use  to find the Transaction Worksheet page and click on it to open it.
    2. Add a new transaction entry.
    3. Make sure that Status is New.
    4. Select Actions | Post Entries. This should result in the error about Status needing to be Verified.
    5. Change the Status field to Verified.
    6. Repeat step 4 post the entry again. This time it should post without error.
..................Content has been hidden....................

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