I have the following requirement in the Sales Order: The items showed in the Dropdown from the No. and description field should be filtered by information that is in the Sales Header of this Sales Order.
In the Condition part, I can only filter my cases by fields that are already in this particular Sales Line. So no information of the Sales Header is reachable (or is it?):
(the following code is in a page extension to sales order subform).
//my new field
field(BufferNo; BufferNo)
{
ApplicationArea = Basic, Suite;
Caption = 'Custom Nr.';
//LookupPageID = "Option Lookup List";
ShowMandatory = not IsCommentLine;
TableRelation = if (Type = const(" ")) "Standard Text"
else
if (Type = const("G/L Account"), "System-Created Entry" = const(false)) "G/L Account" where("Direct Posting" = const(true), "Account Type" = const(Posting), Blocked = const(false))
else
if (Type = const("G/L Account"), "System-Created Entry" = const(true)) "G/L Account"
else
if (Type = const(Resource)) Resource
else
if (Type = const("Fixed Asset")) "Fixed Asset"
else
if (Type = const("Charge (Item)")) "Item Charge"
else
if (Type = const("Allocation Account")) "Allocation Account"
else
if (Type = const(Item), "Document Type" = filter(<> "Credit Memo" & <> "Return Order"), Debitorenart = const('AUD')) Item where(Blocked = const(false), "Sales Blocked" = const(false), "Item Category Code" = const('STANDARD'))
else
if (Type = const(Item), "Document Type" = filter(<> "Credit Memo" & <> "Return Order"), Debitorenart = const('AT')) Item where(Blocked = const(false), "Sales Blocked" = const(false), "Item Category Code" = const('AT'))
else
if (Type = const(Item), "Document Type" = filter("Credit Memo" | "Return Order")) Item where(Blocked = const(false));
if we look at this line:
if (Type = const(Item), "Document Type" = filter(<> "Credit Memo" & <> "Return Order"), Debitorenart = const('AUD')) Item where(Blocked = const(false), "Sales Blocked" = const(false), "Item Category Code" = const('STANDARD'))
I want to add a condition to a field called "Debitorenart" which is found in the header (field Code[10]). Now my thinking was: I can copy this field into the sales line from the sales header by an eventsub somewhere close to "OnInit" of the Sales Line, so I can grab the information in the TableRelation. But it doesn't work...
The only eventsub that works is OnBeforeInsertEvent or OnAfterInsertEvent. But that's already too late, because the dropdown is usually opened before the Line is inserted. I tried something like OnAfterInitType which is pretty close after normal Init, but it does not write any value into the field. Which confuses me, because somehow it is able to filter for Document type, which had to be given to the Line at one point.
//This one works... But too late
[EventSubscriber(ObjectType::table, 37, OnAfterInsertEvent, '', false, false)]
procedure UpdateLiefzeilen(var Rec: Record "Sales Line"; RunTrigger: Boolean)
var
SalesHeader: Record "Sales Header";
begin
SalesHeader.SetRange("Document Type", Rec."Document Type");
SalesHeader.SetRange("No.", Rec."Document No.");
if SalesHeader.FindFirst() then begin
Rec.Validate("Debitorenart", SalesHeader.Debitorenart);
Rec.Modify();
end;
end;
Does anyone have any suggestion on how to solve this? I only see the following ways:
- Somehow be able to get the information directly from the Sales Header in the Table Relation of the pageextension
- Get the information in the SalesLine directly after Init and have it accessible by TableRelation property
- Maybe work with some kind of BufferTable like the Type field does?
I am really out of ideas here how to solve this and am grateful for any input.